Files
svg-backend/backend/app/db/session.py
2026-03-19 13:39:32 +03:00

23 lines
583 B
Python

from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from app.core.config import settings
engine = create_async_engine(
settings.database_url,
pool_pre_ping=True,
)
AsyncSessionLocal = async_sessionmaker(
bind=engine,
class_=AsyncSession,
expire_on_commit=False,
)
async def db_ping() -> dict:
async with AsyncSessionLocal() as session:
result = await session.execute(text("select 1 as ok"))
row = result.mappings().first()
return {"ok": row["ok"] if row else None}