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.
93 lines
3.0 KiB
Go
93 lines
3.0 KiB
Go
// Code generated by goctl. DO NOT EDIT!
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"gorm.io/plugin/optimisticlock"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx"
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var (
|
|
userGradeFieldNames = builder.RawFieldNames(&UserGrade{})
|
|
userGradeRows = strings.Join(userGradeFieldNames, ",")
|
|
userGradeRowsExpectAutoSet = strings.Join(stringx.Remove(userGradeFieldNames, "`create_time`", "`update_time`"), ",")
|
|
userGradeRowsWithPlaceHolder = strings.Join(stringx.Remove(userGradeFieldNames, "`user_id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
userGradeModel interface {
|
|
gormx.TxModel
|
|
Insert(ctx context.Context, tx *gorm.DB, data *UserGrade) error
|
|
FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserGrade, error)
|
|
Update(ctx context.Context, tx *gorm.DB, data *UserGrade) error
|
|
Delete(ctx context.Context, tx *gorm.DB, userId int64) error
|
|
}
|
|
|
|
defaultUserGradeModel struct {
|
|
gormx.GormConn
|
|
table string
|
|
}
|
|
|
|
UserGrade struct {
|
|
UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID
|
|
Grade int64 `gorm:"column:grade"` // 段位
|
|
Level int64 `gorm:"column:level"` // 段位等级
|
|
Star int64 `gorm:"column:star"` // 等级星级
|
|
BravePoint int64 `gorm:"column:brave_point"` // 骁勇分
|
|
Version optimisticlock.Version `gorm:"column:version"` // 乐观锁
|
|
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
|
|
UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间
|
|
}
|
|
)
|
|
|
|
var UserGradeTableName = "`user_grade`"
|
|
|
|
func newUserGradeModel(conn *gorm.DB) *defaultUserGradeModel {
|
|
return &defaultUserGradeModel{
|
|
GormConn: gormx.NewConn(conn),
|
|
table: UserGradeTableName,
|
|
}
|
|
}
|
|
|
|
func (m *defaultUserGradeModel) Insert(ctx context.Context, tx *gorm.DB, data *UserGrade) error {
|
|
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
|
|
return err
|
|
}
|
|
|
|
func (m *defaultUserGradeModel) FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserGrade, error) {
|
|
var resp UserGrade
|
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&UserGrade{}).Where("`user_id` = ?", userId).Take(&resp).Error
|
|
if err = gormx.WrapSelectErr(err); err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultUserGradeModel) Update(ctx context.Context, tx *gorm.DB, data *UserGrade) error {
|
|
|
|
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
|
|
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
|
|
|
|
}
|
|
|
|
func (m *defaultUserGradeModel) Delete(ctx context.Context, tx *gorm.DB, userId int64) error {
|
|
err := gormx.WithTx(ctx, m.DB, tx).Delete(&UserGrade{}, userId).Error
|
|
|
|
return err
|
|
}
|
|
|
|
func (m *defaultUserGradeModel) tableName() string {
|
|
return m.table
|
|
}
|
|
|
|
func (UserGrade) TableName() string {
|
|
return UserGradeTableName
|
|
}
|