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.

84 lines
2.3 KiB
Go

// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"time"
"gorm.io/gorm"
)
const (
TableNameUserNobility = "`user_nobility`"
)
type (
userNobilityModel interface {
Insert(ctx context.Context, data *UserNobility) error
FindOne(ctx context.Context, userId int64) (*UserNobility, error)
Update(ctx context.Context, data *UserNobility) error
Delete(ctx context.Context, userId int64) error
}
defaultUserNobilityModel struct {
conn *gorm.DB
table string
}
UserNobility struct {
UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID
NobilityLevel int64 `gorm:"column:nobility_level"` // 贵族等级0表示非贵族
Forever BitBool `gorm:"forever"` // 是否永久贵族
StartTime time.Time `gorm:"start_time"` // 开始时间
EndTime time.Time `gorm:"end_time"` // 结束时间
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间
}
)
func newUserNobilityModel(conn *gorm.DB) *defaultUserNobilityModel {
return &defaultUserNobilityModel{
conn: conn,
table: TableNameUserNobility,
}
}
func (m *defaultUserNobilityModel) Insert(ctx context.Context, data *UserNobility) error {
err := m.conn.WithContext(ctx).Create(&data).Error
return err
}
func (m *defaultUserNobilityModel) FindOne(ctx context.Context, userId int64) (*UserNobility, error) {
var resp UserNobility
err := m.conn.WithContext(ctx).Model(&UserNobility{}).Where("`user_id` = ?", userId).Take(&resp).Error
switch err {
case nil:
return &resp, nil
case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserNobilityModel) Update(ctx context.Context, data *UserNobility) error {
err := m.conn.WithContext(ctx).Save(data).Error
return err
}
func (m *defaultUserNobilityModel) Delete(ctx context.Context, userId int64) error {
err := m.conn.WithContext(ctx).Delete(&UserNobility{}, userId).Error
return err
}
func (m *defaultUserNobilityModel) tableName() string {
return m.table
}
func (UserNobility) TableName() string {
return TableNameUserNobility
}