Game7 去掉上级邀请id限制
This commit is contained in:
45
internal/model/nh_role_model.go
Executable file
45
internal/model/nh_role_model.go
Executable file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ NhRoleModel = (*customNhRoleModel)(nil)
|
||||
|
||||
type (
|
||||
// NhRoleModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhRoleModel.
|
||||
NhRoleModel interface {
|
||||
nhRoleModel
|
||||
withSession(session sqlx.Session) NhRoleModel
|
||||
AccountExist(ctx context.Context, account string) (bool, error)
|
||||
}
|
||||
|
||||
customNhRoleModel struct {
|
||||
*defaultNhRoleModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhRoleModel) AccountExist(ctx context.Context, account string) (bool, error) {
|
||||
query := fmt.Sprintf("select count(*) as `count` from %s where `account` = ?", m.table)
|
||||
var count int64
|
||||
err := m.conn.QueryRowCtx(ctx, &count, query, account)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return false, err
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// NewNhRoleModel returns a model for the database table.
|
||||
func NewNhRoleModel(conn sqlx.SqlConn) NhRoleModel {
|
||||
return &customNhRoleModel{
|
||||
defaultNhRoleModel: newNhRoleModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhRoleModel) withSession(session sqlx.Session) NhRoleModel {
|
||||
return NewNhRoleModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
Reference in New Issue
Block a user