109 lines
3.8 KiB
Go
Executable File
109 lines
3.8 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
|
// versions:
|
|
// goctl version: 1.7.3
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
nhUserFieldNames = builder.RawFieldNames(&NhUser{})
|
|
nhUserRows = strings.Join(nhUserFieldNames, ",")
|
|
nhUserRowsExpectAutoSet = strings.Join(stringx.Remove(nhUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
nhUserRowsWithPlaceHolder = strings.Join(stringx.Remove(nhUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
nhUserModel interface {
|
|
Insert(ctx context.Context, data *NhUser) (sql.Result, error)
|
|
FindOne(ctx context.Context, id uint) (*NhUser, error)
|
|
FindOneByEmail(ctx context.Context, email string) (*NhUser, error)
|
|
Update(ctx context.Context, data *NhUser) error
|
|
Delete(ctx context.Context, id uint) error
|
|
}
|
|
|
|
defaultNhUserModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
NhUser struct {
|
|
Id uint `db:"id"`
|
|
Email string `db:"email"` // 邮箱
|
|
Password string `db:"password"` // 密码
|
|
CreateTime sql.NullInt64 `db:"create_time"` // 创建时间
|
|
InviteId int `db:"invite_id"` // 邀请码/测试码ID
|
|
LastLoginTime sql.NullInt64 `db:"last_login_time"` // 最后登陆时间
|
|
LastLoginIp string `db:"last_login_ip"` // 最后登录IP
|
|
Remarks sql.NullString `db:"remarks"` // 备注
|
|
Status uint8 `db:"status"` // 用户状态 1 正常 2 禁止
|
|
IsOpenSeason int8 `db:"is_open_season"` // 是否已开启赛季
|
|
}
|
|
)
|
|
|
|
func newNhUserModel(conn sqlx.SqlConn) *defaultNhUserModel {
|
|
return &defaultNhUserModel{
|
|
conn: conn,
|
|
table: "`nh_user`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhUserModel) Delete(ctx context.Context, id uint) error {
|
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultNhUserModel) FindOne(ctx context.Context, id uint) (*NhUser, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhUserRows, m.table)
|
|
var resp NhUser
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhUserModel) FindOneByEmail(ctx context.Context, email string) (*NhUser, error) {
|
|
var resp NhUser
|
|
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", nhUserRows, m.table)
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhUserModel) Insert(ctx context.Context, data *NhUser) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, nhUserRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Email, data.Password, data.InviteId, data.LastLoginTime, data.LastLoginIp, data.Remarks, data.Status, data.IsOpenSeason)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultNhUserModel) Update(ctx context.Context, newData *NhUser) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhUserRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, newData.Email, newData.Password, newData.InviteId, newData.LastLoginTime, newData.LastLoginIp, newData.Remarks, newData.Status, newData.IsOpenSeason, newData.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultNhUserModel) tableName() string {
|
|
return m.table
|
|
}
|