mirror of
https://github.com/R0m1k3/Reviflow.git
synced 2026-10-12 09:46:45 +02:00
16 lines
593 B
Python
16 lines
593 B
Python
from collections.abc import AsyncGenerator
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
from sqlmodel import SQLModel
|
|
from app.config import settings
|
|
|
|
engine = create_async_engine(settings.DATABASE_URL)
|
|
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)
|
|
|
|
async def create_db_and_tables():
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(SQLModel.metadata.create_all)
|
|
|
|
async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
|
|
async with async_session_maker() as session:
|
|
yield session
|