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.
91 lines
2.7 KiB
Go
91 lines
2.7 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 (
|
|
userCoinFieldNames = builder.RawFieldNames(&UserCoin{})
|
|
userCoinRows = strings.Join(userCoinFieldNames, ",")
|
|
userCoinRowsExpectAutoSet = strings.Join(stringx.Remove(userCoinFieldNames, "`create_time`", "`update_time`"), ",")
|
|
userCoinRowsWithPlaceHolder = strings.Join(stringx.Remove(userCoinFieldNames, "`user_id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
userCoinModel interface {
|
|
gormx.TxModel
|
|
Insert(ctx context.Context, tx *gorm.DB, data *UserCoin) error
|
|
FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserCoin, error)
|
|
Update(ctx context.Context, tx *gorm.DB, data *UserCoin) error
|
|
Delete(ctx context.Context, tx *gorm.DB, userId int64) error
|
|
}
|
|
|
|
defaultUserCoinModel struct {
|
|
gormx.GormConn
|
|
table string
|
|
}
|
|
|
|
UserCoin struct {
|
|
UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID
|
|
Coin int64 `gorm:"column:coin"` // 弹币 1:100
|
|
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 UserCoinTableName = "`user_coin`"
|
|
|
|
func newUserCoinModel(conn *gorm.DB) *defaultUserCoinModel {
|
|
return &defaultUserCoinModel{
|
|
GormConn: gormx.NewConn(conn),
|
|
table: UserCoinTableName,
|
|
}
|
|
}
|
|
|
|
func (m *defaultUserCoinModel) Insert(ctx context.Context, tx *gorm.DB, data *UserCoin) error {
|
|
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
|
|
return err
|
|
}
|
|
|
|
func (m *defaultUserCoinModel) FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserCoin, error) {
|
|
var resp UserCoin
|
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&UserCoin{}).Where("`user_id` = ?", userId).Take(&resp).Error
|
|
err = gormx.WrapSelectErr(err)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultUserCoinModel) Update(ctx context.Context, tx *gorm.DB, data *UserCoin) error {
|
|
|
|
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
|
|
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
|
|
|
|
}
|
|
|
|
func (m *defaultUserCoinModel) Delete(ctx context.Context, tx *gorm.DB, userId int64) error {
|
|
err := gormx.WithTx(ctx, m.DB, tx).Delete(&UserCoin{}, userId).Error
|
|
|
|
return err
|
|
}
|
|
|
|
func (m *defaultUserCoinModel) tableName() string {
|
|
return m.table
|
|
}
|
|
|
|
func (UserCoin) TableName() string {
|
|
return UserCoinTableName
|
|
}
|