from sqlmodel import select from sqlmodel.ext.asyncio.session import AsyncSession from sqlalchemy.ext.asyncio import create_async_engine from sqlalchemy.orm import sessionmaker from ..config import config import logging logger = logging.getLogger('sqlalchemy.engine') logger.setLevel(logging.DEBUG) async_engine = create_async_engine(config.DATABASE_URI) async_session = sessionmaker[AsyncSession]( async_engine, class_=AsyncSession, expire_on_commit=False ) async def init_db(session: AsyncSession) -> None: from app.models import User, Language,Role user = (await session.exec( select(User).where(User.id == config.ADMIN_TELEGRAM_ID) )).first() if not user: await User.create(session, User( id = config.ADMIN_TELEGRAM_ID, lang = Language.DEFAULT, roles = [Role.SUPER_USER], name = "Admin"), commit = True) async def get_db() -> AsyncSession: # type: ignore async with async_session() as session: yield session