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.
102 lines
3.3 KiB
Go
102 lines
3.3 KiB
Go
2 years ago
|
// Code generated by goctl. DO NOT EDIT!
|
||
|
|
||
|
package model
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"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 (
|
||
|
userTitleFieldNames = builder.RawFieldNames(&UserTitle{})
|
||
|
userTitleRows = strings.Join(userTitleFieldNames, ",")
|
||
|
userTitleRowsExpectAutoSet = strings.Join(stringx.Remove(userTitleFieldNames, "`create_time`", "`update_time`"), ",")
|
||
|
userTitleRowsWithPlaceHolder = strings.Join(stringx.Remove(userTitleFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
userTitleModel interface {
|
||
|
gormx.TxModel
|
||
|
Insert(ctx context.Context, tx *gorm.DB, data *UserTitle) error
|
||
|
FindOne(ctx context.Context, tx *gorm.DB, id int64) (*UserTitle, error)
|
||
|
FindOneByUserIdTitleId(ctx context.Context, tx *gorm.DB, userId int64, titleId int64) (*UserTitle, error)
|
||
|
Update(ctx context.Context, tx *gorm.DB, data *UserTitle) error
|
||
|
Delete(ctx context.Context, tx *gorm.DB, id int64) error
|
||
|
}
|
||
|
|
||
|
defaultUserTitleModel struct {
|
||
|
gormx.GormConn
|
||
|
table string
|
||
|
}
|
||
|
|
||
|
UserTitle struct {
|
||
|
Id int64 `gorm:"column:id;primaryKey"` // 主键ID
|
||
|
UserId int64 `gorm:"column:user_id"` // 用户ID
|
||
|
TitleId int64 `gorm:"column:title_id"` // 称号ID
|
||
|
Sort int64 `gorm:"column:sort"` // 排序号
|
||
|
Type string `gorm:"type"` // 称号类型
|
||
|
Forever BitBool `gorm:"forever"` // 永久
|
||
|
StartTime time.Time `gorm:"column:start_time;default:null"` // 开始时间
|
||
|
EndTime time.Time `gorm:"column:end_time;default:null"` // 结束时间
|
||
|
}
|
||
|
)
|
||
|
|
||
|
var UserTitleTableName = "`user_title`"
|
||
|
|
||
|
func newUserTitleModel(conn *gorm.DB) *defaultUserTitleModel {
|
||
|
return &defaultUserTitleModel{
|
||
|
GormConn: gormx.NewConn(conn),
|
||
|
table: UserTitleTableName,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (m *defaultUserTitleModel) Insert(ctx context.Context, tx *gorm.DB, data *UserTitle) error {
|
||
|
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (m *defaultUserTitleModel) FindOne(ctx context.Context, tx *gorm.DB, id int64) (*UserTitle, error) {
|
||
|
var resp UserTitle
|
||
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&UserTitle{}).Where("`id` = ?", id).Take(&resp).Error
|
||
|
if err = gormx.WrapSelectErr(err); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &resp, nil
|
||
|
}
|
||
|
|
||
|
func (m *defaultUserTitleModel) FindOneByUserIdTitleId(ctx context.Context, tx *gorm.DB, userId int64, titleId int64) (*UserTitle, error) {
|
||
|
var resp UserTitle
|
||
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&UserTitle{}).Where("`user_id` = ? and `title_id` = ?", userId, titleId).Take(&resp).Error
|
||
|
if err = gormx.WrapSelectErr(err); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &resp, nil
|
||
|
}
|
||
|
|
||
|
func (m *defaultUserTitleModel) Update(ctx context.Context, tx *gorm.DB, data *UserTitle) error {
|
||
|
|
||
|
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
|
||
|
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
|
||
|
|
||
|
}
|
||
|
|
||
|
func (m *defaultUserTitleModel) Delete(ctx context.Context, tx *gorm.DB, id int64) error {
|
||
|
err := gormx.WithTx(ctx, m.DB, tx).Delete(&UserTitle{}, id).Error
|
||
|
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (m *defaultUserTitleModel) tableName() string {
|
||
|
return m.table
|
||
|
}
|
||
|
|
||
|
func (UserTitle) TableName() string {
|
||
|
return UserTitleTableName
|
||
|
}
|