Files
36Wisdom/biz/dao/dao_admin_user.go
T
2026-08-14 16:11:10 +08:00

33 lines
879 B
Go

package dao
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"36wisdom/biz/consts"
"36wisdom/biz/model/entity"
"36wisdom/common"
)
type adminUserDao struct{ common.BaseDao }
var AdminUser = &adminUserDao{BaseDao: common.BaseDao{Table: consts.TableAdminUser}}
func (d *adminUserDao) Init(ctx context.Context) error {
_, err := g.DB().Exec(ctx, `
CREATE TABLE IF NOT EXISTS admin_user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
status INTEGER NOT NULL DEFAULT 1,
created_at DATETIME
);`)
return err
}
// GetByUsername 按用户名查管理员(登录用);不存在返回 nil, nil。
func (d *adminUserDao) GetByUsername(ctx context.Context, username string) (*entity.AdminUser, error) {
return common.GetOne[entity.AdminUser](d.Model().Ctx(ctx).Where("username", username))
}