connect database

This commit is contained in:
2025-09-27 09:13:20 +03:00
parent 5982351dd2
commit 1a49545fff
16 changed files with 180 additions and 38 deletions

View File

@@ -0,0 +1,22 @@
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from .models import User
async def get_user_by_tg_id(session: AsyncSession, user_tg_id: int) -> User | None:
result = await session.execute(select(User).where(User.tg_id == user_tg_id))
return result.scalar_one_or_none()
async def create_user(
session: AsyncSession,
tg_id: int,
fullname: str,
phone: str = "",
role: str = "user",
) -> User:
user = User(tg_id=tg_id, fullname=fullname, role=role, phone=phone)
session.add(user)
await session.commit()
return user