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.

89 lines
2.4 KiB
Go

3 years ago
// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"strings"
"time"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormx"
3 years ago
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stringx"
3 years ago
"gorm.io/gorm"
3 years ago
)
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
3 years ago
}
defaultUserModel struct {
gormx.GormConn
3 years ago
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"` // 更新时间
3 years ago
}
)
var UserTableName = "`user`"
3 years ago
func newUserModel(conn *gorm.DB) *defaultUserModel {
3 years ago
return &defaultUserModel{
GormConn: gormx.NewConn(conn),
table: UserTableName,
3 years ago
}
}
func (m *defaultUserModel) Insert(ctx context.Context, tx *gorm.DB, data *User) error {
err := gormx.WithTx(ctx, m.DB, tx).Create(&data).Error
3 years ago
return err
3 years ago
}
func (m *defaultUserModel) FindOne(ctx context.Context, tx *gorm.DB, id int64) (*User, error) {
3 years ago
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 {
3 years ago
return nil, err
}
return &resp, nil
3 years ago
}
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)
3 years ago
}
func (m *defaultUserModel) Delete(ctx context.Context, tx *gorm.DB, id int64) error {
err := gormx.WithTx(ctx, m.DB, tx).Delete(&User{}, id).Error
3 years ago
3 years ago
return err
}
func (m *defaultUserModel) tableName() string {
return m.table
}
3 years ago
func (User) TableName() string {
return UserTableName
3 years ago
}