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.9 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 (
userIntegralFieldNames = builder.RawFieldNames(&UserIntegral{})
userIntegralRows = strings.Join(userIntegralFieldNames, ",")
userIntegralRowsExpectAutoSet = strings.Join(stringx.Remove(userIntegralFieldNames, "`create_time`", "`update_time`"), ",")
userIntegralRowsWithPlaceHolder = strings.Join(stringx.Remove(userIntegralFieldNames, "`user_id`", "`create_time`", "`update_time`"), "=?,") + "=?"
)
type (
userIntegralModel interface {
gormx.TxModel
Insert(ctx context.Context, tx *gorm.DB, data *UserIntegral) error
FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserIntegral, error)
Update(ctx context.Context, tx *gorm.DB, data *UserIntegral) error
Delete(ctx context.Context, tx *gorm.DB, userId int64) error
}
defaultUserIntegralModel struct {
gormx.GormConn
table string
}
UserIntegral struct {
UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID
Integral int64 `gorm:"column:integral"` // 用户积分1 RMB1000
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 UserIntegralTableName = "`user_integral`"
func newUserIntegralModel(conn *gorm.DB) *defaultUserIntegralModel {
return &defaultUserIntegralModel{
GormConn: gormx.NewConn(conn),
table: UserIntegralTableName,
}
}
func (m *defaultUserIntegralModel) Insert(ctx context.Context, tx *gorm.DB, data *UserIntegral) error {
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
return err
}
func (m *defaultUserIntegralModel) FindOne(ctx context.Context, tx *gorm.DB, userId int64) (*UserIntegral, error) {
var resp UserIntegral
err := gormx.WithTx(ctx, m.DB, tx).Model(&UserIntegral{}).Where("`user_id` = ?", userId).Take(&resp).Error
result, err := gormx.WrapSelectResult(err, &resp)
if err != nil {
return nil, err
}
return result.(*UserIntegral), nil
}
func (m *defaultUserIntegralModel) Update(ctx context.Context, tx *gorm.DB, data *UserIntegral) error {
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
}
func (m *defaultUserIntegralModel) Delete(ctx context.Context, tx *gorm.DB, userId int64) error {
err := gormx.WithTx(ctx, m.DB, tx).Delete(&UserIntegral{}, userId).Error
return err
}
func (m *defaultUserIntegralModel) tableName() string {
return m.table
}
func (UserIntegral) TableName() string {
return UserIntegralTableName
}