123456789101112131415 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from sqlalchemy import select
- from sqlalchemy.ext.asyncio import AsyncSession
- async def get_user_by_username(db: AsyncSession, username: str, user_model):
- stmt = select(user_model).where(user_model.username == username).limit(1)
- try:
- result = await db.execute(stmt)
- finally:
- await db.close()
- return result.scalar()
|