|
|
|
// 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 (
|
|
|
|
userFieldNames = builder.RawFieldNames(&User{})
|
|
|
|
userRows = strings.Join(userFieldNames, ",")
|
|
|
|
userRowsExpectAutoSet = strings.Join(stringx.Remove(userFieldNames, "`create_time`", "`update_time`"), ",")
|
|
|
|
userRowsWithPlaceHolder = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
userModel interface {
|
|
|
|
gormx.TxModel
|
|
|
|
Insert(ctx context.Context, tx *gorm.DB, data *User) error
|
|
|
|
FindOne(ctx context.Context, tx *gorm.DB, id int64) (*User, error)
|
|
|
|
Update(ctx context.Context, tx *gorm.DB, data *User) error
|
|
|
|
Delete(ctx context.Context, tx *gorm.DB, id int64) error
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultUserModel struct {
|
|
|
|
gormx.GormConn
|
|
|
|
table string
|
|
|
|
}
|
|
|
|
|
|
|
|
User struct {
|
|
|
|
Id int64 `gorm:"column:id;primaryKey"` // 用户ID
|
|
|
|
Username string `gorm:"column:username"` // 用户名
|
|
|
|
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
|
|
|
|
UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
var UserTableName = "`user`"
|
|
|
|
|
|
|
|
func newUserModel(conn *gorm.DB) *defaultUserModel {
|
|
|
|
return &defaultUserModel{
|
|
|
|
GormConn: gormx.NewConn(conn),
|
|
|
|
table: UserTableName,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserModel) Insert(ctx context.Context, tx *gorm.DB, data *User) error {
|
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserModel) FindOne(ctx context.Context, tx *gorm.DB, id int64) (*User, error) {
|
|
|
|
var resp User
|
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&User{}).Where("`id` = ?", id).Take(&resp).Error
|
|
|
|
err = gormx.WrapSelectErr(err)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserModel) Update(ctx context.Context, tx *gorm.DB, data *User) error {
|
|
|
|
|
|
|
|
result := gormx.WithTx(ctx, m.DB, tx).Save(data)
|
|
|
|
return gormx.WrapUpdateErr(result.Error, result.RowsAffected)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserModel) Delete(ctx context.Context, tx *gorm.DB, id int64) error {
|
|
|
|
err := gormx.WithTx(ctx, m.DB, tx).Delete(&User{}, id).Error
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *defaultUserModel) tableName() string {
|
|
|
|
return m.table
|
|
|
|
}
|
|
|
|
|
|
|
|
func (User) TableName() string {
|
|
|
|
return UserTableName
|
|
|
|
}
|