125 lines
4.3 KiB
Go
125 lines
4.3 KiB
Go
// Code generated by goctl. DO NOT EDIT.
|
|
// versions:
|
|
// goctl version: 1.7.3
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
nhCastileTokenFieldNames = builder.RawFieldNames(&NhCastileToken{})
|
|
nhCastileTokenRows = strings.Join(nhCastileTokenFieldNames, ",")
|
|
nhCastileTokenRowsExpectAutoSet = strings.Join(stringx.Remove(nhCastileTokenFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
nhCastileTokenRowsWithPlaceHolder = strings.Join(stringx.Remove(nhCastileTokenFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
nhCastileTokenModel interface {
|
|
Insert(ctx context.Context, data *NhCastileToken) (sql.Result, error)
|
|
FindOne(ctx context.Context, id uint) (*NhCastileToken, error)
|
|
FindOneByEmail(ctx context.Context, email string) (*NhCastileToken, error)
|
|
FindOneByUid(ctx context.Context, uid uint) (*NhCastileToken, error)
|
|
Update(ctx context.Context, data *NhCastileToken) error
|
|
Delete(ctx context.Context, id uint) error
|
|
}
|
|
|
|
defaultNhCastileTokenModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
NhCastileToken struct {
|
|
Id uint `db:"id"`
|
|
Uid uint `db:"uid"` // 用户id
|
|
Email string `db:"email"` // 账号
|
|
Amount1 uint `db:"amount1"` // 一测奖励
|
|
Amount2 uint `db:"amount2"` // 二测奖励
|
|
Amount3 uint `db:"amount3"` // 三测奖励
|
|
Total uint `db:"total"` // 总奖励
|
|
Transfer uint `db:"transfer"` // 已提取到游戏内
|
|
CreatedAt time.Time `db:"created_at"` // 创建时间
|
|
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
|
}
|
|
)
|
|
|
|
func newNhCastileTokenModel(conn sqlx.SqlConn) *defaultNhCastileTokenModel {
|
|
return &defaultNhCastileTokenModel{
|
|
conn: conn,
|
|
table: "`nh_castile_token`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhCastileTokenModel) 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 *defaultNhCastileTokenModel) FindOne(ctx context.Context, id uint) (*NhCastileToken, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhCastileTokenRows, m.table)
|
|
var resp NhCastileToken
|
|
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 *defaultNhCastileTokenModel) FindOneByEmail(ctx context.Context, email string) (*NhCastileToken, error) {
|
|
var resp NhCastileToken
|
|
query := fmt.Sprintf("select %s from %s where `email` = ? limit 1", nhCastileTokenRows, 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 *defaultNhCastileTokenModel) FindOneByUid(ctx context.Context, uid uint) (*NhCastileToken, error) {
|
|
var resp NhCastileToken
|
|
query := fmt.Sprintf("select %s from %s where `uid` = ? limit 1", nhCastileTokenRows, m.table)
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, uid)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhCastileTokenModel) Insert(ctx context.Context, data *NhCastileToken) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, nhCastileTokenRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.Email, data.Amount1, data.Amount2, data.Amount3, data.Total, data.Transfer)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultNhCastileTokenModel) Update(ctx context.Context, newData *NhCastileToken) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhCastileTokenRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.Email, newData.Amount1, newData.Amount2, newData.Amount3, newData.Total, newData.Transfer, newData.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultNhCastileTokenModel) tableName() string {
|
|
return m.table
|
|
}
|