Files
novatask/internal/model/nh_role_model.go
2025-01-15 16:23:49 +08:00

46 lines
1.2 KiB
Go
Executable File

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))
}