// 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 ( userIntegralModel interface { Insert(ctx context.Context, data *UserIntegral) error FindOne(ctx context.Context, integral int64) (*UserIntegral, error) Update(ctx context.Context, data *UserIntegral) error Delete(ctx context.Context, integral int64) error } defaultUserIntegralModel struct { conn *gorm.DB table string } UserIntegral struct { UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID Integral int64 `gorm:"column:integral"` // 用户积分,1 RMB:1000 CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间 UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间 } ) func newUserIntegralModel(conn *gorm.DB) *defaultUserIntegralModel { return &defaultUserIntegralModel{ conn: conn, table: "`user_integral`", } } func (m *defaultUserIntegralModel) Insert(ctx context.Context, data *UserIntegral) error { err := m.conn.WithContext(ctx).Create(&data).Error return err } func (m *defaultUserIntegralModel) FindOne(ctx context.Context, integral int64) (*UserIntegral, error) { var resp UserIntegral err := m.conn.WithContext(ctx).Model(&UserIntegral{}).Where("`integral` = ?", integral).Take(&resp).Error switch err { case nil: return &resp, nil case gormc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultUserIntegralModel) Update(ctx context.Context, data *UserIntegral) error { err := m.conn.WithContext(ctx).Save(data).Error return err } func (m *defaultUserIntegralModel) Delete(ctx context.Context, integral int64) error { err := m.conn.WithContext(ctx).Delete(&UserIntegral{}, integral).Error return err } func (m *defaultUserIntegralModel) tableName() string { return m.table } func (UserIntegral) TableName() string { model := newUserIntegralModel(nil) return model.tableName() }