You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
3 years ago
|
// Code generated by goctl. DO NOT EDIT!
|
||
|
|
||
|
package model
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
|
||
|
"time"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
rankPvpModel interface {
|
||
|
Insert(ctx context.Context, data *RankPvp) error
|
||
|
FindOne(ctx context.Context, id int64) (*RankPvp, error)
|
||
|
FindOneByUserIdRankType(ctx context.Context, userId int64, rankType int64) (*RankPvp, error)
|
||
|
Update(ctx context.Context, data *RankPvp) error
|
||
|
Delete(ctx context.Context, id int64) error
|
||
|
}
|
||
|
|
||
|
defaultRankPvpModel struct {
|
||
|
conn *gorm.DB
|
||
|
table string
|
||
|
}
|
||
|
|
||
|
RankPvp struct {
|
||
|
Id int64 `gorm:"column:id"` // 主键
|
||
|
UserId int64 `gorm:"column:user_id"` // 用户ID
|
||
|
RankType int64 `gorm:"column:rank_type"` // 类型 1: 伤害 2: 名将次数 3: 击杀单位 4: 击杀玩家
|
||
|
Score int64 `gorm:"column:score"` // 伤害量
|
||
|
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
|
||
|
UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func newRankPvpModel(conn *gorm.DB) *defaultRankPvpModel {
|
||
|
return &defaultRankPvpModel{
|
||
|
conn: conn,
|
||
|
table: "`rank_pvp`",
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *defaultRankPvpModel) Insert(ctx context.Context, data *RankPvp) error {
|
||
|
err := m.conn.WithContext(ctx).Create(&data).Error
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (m *defaultRankPvpModel) FindOne(ctx context.Context, id int64) (*RankPvp, error) {
|
||
|
var resp RankPvp
|
||
|
err := m.conn.WithContext(ctx).Model(&RankPvp{}).Where("`id` = ?", id).Take(&resp).Error
|
||
|
switch err {
|
||
|
case nil:
|
||
|
return &resp, nil
|
||
|
case gormc.ErrNotFound:
|
||
|
return nil, ErrNotFound
|
||
|
default:
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *defaultRankPvpModel) FindOneByUserIdRankType(ctx context.Context, userId int64, rankType int64) (*RankPvp, error) {
|
||
|
var resp RankPvp
|
||
|
err := m.conn.WithContext(ctx).Model(&RankPvp{}).Where("`user_id` = ? and `rank_type` = ?", userId, rankType).Take(&resp).Error
|
||
|
switch err {
|
||
|
case nil:
|
||
|
return &resp, nil
|
||
|
case gormc.ErrNotFound:
|
||
|
return nil, ErrNotFound
|
||
|
default:
|
||
|
return nil, err
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *defaultRankPvpModel) Update(ctx context.Context, data *RankPvp) error {
|
||
|
err := m.conn.WithContext(ctx).Save(data).Error
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (m *defaultRankPvpModel) Delete(ctx context.Context, id int64) error {
|
||
|
err := m.conn.WithContext(ctx).Delete(&RankPvp{}, id).Error
|
||
|
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (m *defaultRankPvpModel) tableName() string {
|
||
|
return m.table
|
||
|
}
|
||
|
|
||
|
func (RankPvp) TableName() string {
|
||
|
model := newRankPvpModel(nil)
|
||
|
return model.tableName()
|
||
|
}
|