54 lines
1.8 KiB
Go
Executable File
54 lines
1.8 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ NhStakePointsLogModel = (*customNhStakePointsLogModel)(nil)
|
|
|
|
type (
|
|
// NhStakePointsLogModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customNhStakePointsLogModel.
|
|
NhStakePointsLogModel interface {
|
|
nhStakePointsLogModel
|
|
WithSession(session sqlx.Session) NhStakePointsLogModel
|
|
List(ctx context.Context, uid uint, roleId uint64, page, pageSize int) ([]*NhStakePointsLog, error)
|
|
}
|
|
|
|
customNhStakePointsLogModel struct {
|
|
*defaultNhStakePointsLogModel
|
|
}
|
|
)
|
|
|
|
func (m *customNhStakePointsLogModel) List(ctx context.Context, uid uint, roleId uint64, page, pageSize int) ([]*NhStakePointsLog, error) {
|
|
var query string
|
|
var result []*NhStakePointsLog
|
|
var err error
|
|
if roleId == 0 {
|
|
query = fmt.Sprintf("select %s from %s where uid = ? order by id desc limit ?, ?", nhStakePointsLogRows, m.table)
|
|
err = m.conn.QueryRowsCtx(ctx, &result, query, uid, (page-1)*pageSize, pageSize)
|
|
} else {
|
|
query = fmt.Sprintf("select %s from %s where uid = ? and role_id = ? order by id desc limit ?, ?", nhStakePointsLogRows, m.table)
|
|
err = m.conn.QueryRowsCtx(ctx, &result, query, uid, roleId, (page-1)*pageSize, pageSize)
|
|
}
|
|
|
|
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// NewNhStakePointsLogModel returns a model for the database table.
|
|
func NewNhStakePointsLogModel(conn sqlx.SqlConn) NhStakePointsLogModel {
|
|
return &customNhStakePointsLogModel{
|
|
defaultNhStakePointsLogModel: newNhStakePointsLogModel(conn),
|
|
}
|
|
}
|
|
|
|
func (m *customNhStakePointsLogModel) WithSession(session sqlx.Session) NhStakePointsLogModel {
|
|
return NewNhStakePointsLogModel(sqlx.NewSqlConnFromSession(session))
|
|
}
|