Initial commit: svg backend
This commit is contained in:
0
backend/app/db/__init__.py
Normal file
0
backend/app/db/__init__.py
Normal file
5
backend/app/db/base.py
Normal file
5
backend/app/db/base.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
22
backend/app/db/session.py
Normal file
22
backend/app/db/session.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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}
|
||||
Reference in New Issue
Block a user