// Code generated by goctl. DO NOT EDIT! package model import ( "context" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" "gorm.io/plugin/optimisticlock" "strings" "time" "github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stringx" "gorm.io/gorm" ) var ( userGiftPackFieldNames = builder.RawFieldNames(&UserGiftPack{}) userGiftPackRows = strings.Join(userGiftPackFieldNames, ",") userGiftPackRowsExpectAutoSet = strings.Join(stringx.Remove(userGiftPackFieldNames, "`create_time`", "`update_time`"), ",") userGiftPackRowsWithPlaceHolder = strings.Join(stringx.Remove(userGiftPackFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?" ) type ( userGiftPackModel interface { Insert(ctx context.Context, data *UserGiftPack) error FindOne(ctx context.Context, id int64) (*UserGiftPack, error) Update(ctx context.Context, data *UserGiftPack) error Delete(ctx context.Context, id int64) error } defaultUserGiftPackModel struct { conn *gorm.DB table string } UserGiftPack struct { Id int64 `gorm:"column:id;primaryKey"` // 主键 UserId int64 `gorm:"column:user_id"` // 用户ID PackType string `gorm:"column:pack_type"` // 礼包类型 PackContent string `gorm:"column:pack_content"` // 礼包内容(冗余) DrawCount int64 `gorm:"column:draw_count"` // 已领取数目 DrawTime time.Time `gorm:"column:draw_time;default:null"` // 领取时间 Version optimisticlock.Version `gorm:"column:version"` // 乐观锁,版本号 } ) func newUserGiftPackModel(conn *gorm.DB) *defaultUserGiftPackModel { return &defaultUserGiftPackModel{ conn: conn, table: "`user_gift_pack`", } } func (m *defaultUserGiftPackModel) Insert(ctx context.Context, data *UserGiftPack) error { err := m.conn.WithContext(ctx).Create(&data).Error return err } func (m *defaultUserGiftPackModel) FindOne(ctx context.Context, id int64) (*UserGiftPack, error) { var resp UserGiftPack err := m.conn.WithContext(ctx).Model(&UserGiftPack{}).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 *defaultUserGiftPackModel) Update(ctx context.Context, data *UserGiftPack) error { err := m.conn.WithContext(ctx).Save(data).Error return err } func (m *defaultUserGiftPackModel) Delete(ctx context.Context, id int64) error { err := m.conn.WithContext(ctx).Delete(&UserGiftPack{}, id).Error return err } func (m *defaultUserGiftPackModel) tableName() string { return m.table } func (UserGiftPack) TableName() string { model := newUserGiftPackModel(nil) return model.tableName() }