// Code generated by goctl. DO NOT EDIT! package model import ( "context" "git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc" "strings" "time" "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 { Insert(ctx context.Context, data *User) error FindOne(ctx context.Context, id int64) (*User, error) Update(ctx context.Context, data *User) error Delete(ctx context.Context, id int64) error } defaultUserModel struct { conn *gorm.DB table string } User struct { Id int64 `gorm:"column:id"` // 用户ID Username string `gorm:"column:username"` // 用户名 CreateTime time.Time `gorm:"column:create_time"` // 创建时间 UpdateTime time.Time `gorm:"column:update_time"` // 更新时间 } ) func newUserModel(conn *gorm.DB) *defaultUserModel { return &defaultUserModel{ conn: conn, table: "`user`", } } func (m *defaultUserModel) Insert(ctx context.Context, data *User) error { err := m.conn.WithContext(ctx).Save(&data).Error return err } func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error) { var resp User err := m.conn.WithContext(ctx).Model(&User{}).Where("`id` = ?", id).Take(&resp).Error switch err { case nil: return &resp, nil case gormc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultUserModel) Update(ctx context.Context, data *User) error { err := m.conn.WithContext(ctx).Save(data).Error return err } func (m *defaultUserModel) Delete(ctx context.Context, id int64) error { err := m.conn.WithContext(ctx).Delete(&User{}, id).Error return err } func (m *defaultUserModel) tableName() string { return m.table } func (User) TableName() string { model := defaultUserModel{} return model.tableName() }