language-learning-app/api/app/outbound/postgres/repositories/user_repository.py

18 lines
524 B
Python
Raw Normal View History

from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from ..entities.user_entity import User
async def create(db: AsyncSession, email: str, hashed_password: str) -> User:
user = User(email=email, hashed_password=hashed_password)
db.add(user)
await db.commit()
await db.refresh(user)
return user
async def get_by_email(db: AsyncSession, email: str) -> User | None:
result = await db.execute(select(User).where(User.email == email))
return result.scalar_one_or_none()