mirror of
https://github.com/yogeshojha/rengine.git
synced 2026-09-30 21:54:57 +02:00
27 lines
600 B
Python
27 lines
600 B
Python
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,
|
|
echo=settings.DEBUG,
|
|
future=True,
|
|
)
|
|
|
|
async_db_session = async_sessionmaker(
|
|
engine,
|
|
class_=AsyncSession,
|
|
expire_on_commit=False,
|
|
)
|
|
|
|
|
|
async def init_db() -> None:
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(SQLModel.metadata.create_all)
|
|
|
|
|
|
async def get_session() -> AsyncSession:
|
|
async with async_db_session() as session:
|
|
yield session
|