hashir-qt's picture
Initial backend project structure and core API
0ff2e07
Raw History Blame Contribute Delete
681 Bytes
from collections.abc import AsyncGenerator
from sqlalchemy.ext.asyncio import create_async_engine
from sqlmodel import SQLModel
from sqlmodel.ext.asyncio.session import AsyncSession
from backend.config import settings
engine = create_async_engine(
settings.database_url,
echo=settings.debug,
future=True,
)
async def init_db() -> None:
"""Create all database tables."""
async with engine.begin() as conn:
await conn.run_sync(SQLModel.metadata.create_all)
async def get_session() -> AsyncGenerator[AsyncSession, None]:
"""Dependency for getting async database sessions."""
async with AsyncSession(engine) as session:
yield session