93 lines
3.2 KiB
Go
Executable File
93 lines
3.2 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
||
// versions:
|
||
// goctl version: 1.7.6
|
||
|
||
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 (
|
||
nhStakePointsLogFieldNames = builder.RawFieldNames(&NhStakePointsLog{})
|
||
nhStakePointsLogRows = strings.Join(nhStakePointsLogFieldNames, ",")
|
||
nhStakePointsLogRowsExpectAutoSet = strings.Join(stringx.Remove(nhStakePointsLogFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
nhStakePointsLogRowsWithPlaceHolder = strings.Join(stringx.Remove(nhStakePointsLogFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||
)
|
||
|
||
type (
|
||
nhStakePointsLogModel interface {
|
||
Insert(ctx context.Context, data *NhStakePointsLog) (sql.Result, error)
|
||
FindOne(ctx context.Context, id uint) (*NhStakePointsLog, error)
|
||
Update(ctx context.Context, data *NhStakePointsLog) error
|
||
Delete(ctx context.Context, id uint) error
|
||
}
|
||
|
||
defaultNhStakePointsLogModel struct {
|
||
conn sqlx.SqlConn
|
||
table string
|
||
}
|
||
|
||
NhStakePointsLog struct {
|
||
Id uint `db:"id"`
|
||
Uid uint `db:"uid"` // 用户id
|
||
RoleId uint64 `db:"role_id"` // 角色id
|
||
LevelId uint `db:"level_id"` // 档位id
|
||
Level uint `db:"level"` // 档位
|
||
Points int `db:"points"` // 积分数量
|
||
Action uint8 `db:"action"` // 操作类型:1=质押,2=升级,3=续约,4=解除
|
||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||
}
|
||
)
|
||
|
||
func newNhStakePointsLogModel(conn sqlx.SqlConn) *defaultNhStakePointsLogModel {
|
||
return &defaultNhStakePointsLogModel{
|
||
conn: conn,
|
||
table: "`nh_stake_points_log`",
|
||
}
|
||
}
|
||
|
||
func (m *defaultNhStakePointsLogModel) 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 *defaultNhStakePointsLogModel) FindOne(ctx context.Context, id uint) (*NhStakePointsLog, error) {
|
||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhStakePointsLogRows, m.table)
|
||
var resp NhStakePointsLog
|
||
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 *defaultNhStakePointsLogModel) Insert(ctx context.Context, data *NhStakePointsLog) (sql.Result, error) {
|
||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?)", m.table, nhStakePointsLogRowsExpectAutoSet)
|
||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.RoleId, data.LevelId, data.Level, data.Points, data.Action)
|
||
return ret, err
|
||
}
|
||
|
||
func (m *defaultNhStakePointsLogModel) Update(ctx context.Context, data *NhStakePointsLog) error {
|
||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhStakePointsLogRowsWithPlaceHolder)
|
||
_, err := m.conn.ExecCtx(ctx, query, data.Uid, data.RoleId, data.LevelId, data.Level, data.Points, data.Action, data.Id)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultNhStakePointsLogModel) tableName() string {
|
||
return m.table
|
||
}
|