Files
novatask/internal/model/nh_game_pit_model.go
2024-12-27 18:06:13 +08:00

45 lines
1.1 KiB
Go
Executable File

package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhGamePitModel = (*customNhGamePitModel)(nil)
type (
// NhGamePitModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhGamePitModel.
NhGamePitModel interface {
nhGamePitModel
withSession(session sqlx.Session) NhGamePitModel
UserExist(ctx context.Context, uid uint) bool
}
customNhGamePitModel struct {
*defaultNhGamePitModel
}
)
func (m *customNhGamePitModel) UserExist(ctx context.Context, uid uint) bool {
query := fmt.Sprintf("SELECT `id` FROM %s WHERE `uid` = ? LIMIT 1", m.table)
var id int
err := m.conn.QueryRowCtx(ctx, &id, query, uid)
if err != nil {
return false
}
return id > 0
}
// NewNhGamePitModel returns a model for the database table.
func NewNhGamePitModel(conn sqlx.SqlConn) NhGamePitModel {
return &customNhGamePitModel{
defaultNhGamePitModel: newNhGamePitModel(conn),
}
}
func (m *customNhGamePitModel) withSession(session sqlx.Session) NhGamePitModel {
return NewNhGamePitModel(sqlx.NewSqlConnFromSession(session))
}