репозитории users, chats, messages

This commit is contained in:
2026-10-01 00:06:11 +03:00
parent 82e8fee7f9
commit c4fc878861
3 changed files with 145 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
from uuid import UUID
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from ..db.models import User
async def get_by_username(db: AsyncSession, username: str) -> User | None:
return (
await db.execute(select(User).where(User.username == username))
).scalar_one_or_none()
async def get_by_id(db: AsyncSession, user_id: UUID) -> User | None:
return await db.get(User, user_id)
async def create(
db: AsyncSession, username: str, display_name: str, password_hash: str
) -> User:
user = User(
username=username, display_name=display_name, password_hash=password_hash
)
db.add(user)
await db.commit()
await db.refresh(user)
return user