Untitled

Anonymous
Plain Text
08/29/2025 10:47 AM
648 B
19
Indexable
Never
from sqlmodel import SQLModel
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from app.settings import settings

engine = create_async_engine(settings.DATABASE_URL, echo=True, future=True)
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)

async def init_db():
    # SQLModel metadata -> tabloları & enumları oluştur
    async with engine.begin() as conn:
        await conn.run_sync(SQLModel.metadata.create_all)

# FastAPI dependency
async def get_session() -> AsyncSession:
    async with AsyncSessionLocal() as session:
        yield session
Editor is loading...
Leave a Comment