21 lines
562 B
Python
21 lines
562 B
Python
"""账号 DAO。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.dao.base_dao import BaseDao
|
|
from app.model import Account
|
|
|
|
|
|
class AccountDao(BaseDao[Account]):
|
|
model = Account
|
|
|
|
@classmethod
|
|
def get_by_username(cls, db: Session, username: str, with_deleted: bool = False) -> Account | None:
|
|
stmt = select(Account).where(Account.username == username)
|
|
if not with_deleted:
|
|
stmt = stmt.where(Account.alive())
|
|
return db.scalars(stmt).unique().first()
|