feat: add base FastAPI project structure with static frontend and API v1

This commit is contained in:
Lino Mallevaey
2025-08-18 00:22:50 +02:00
parent ff5026b8f7
commit 49bcb38261
14 changed files with 487 additions and 13 deletions

View File

@@ -0,0 +1,45 @@
from typing import AsyncGenerator, Generator
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.asyncio import AsyncSession
from app.db.engine import engine, async_engine
# =========================
# SYNCHRONOUS SESSION
# =========================
SessionLocal = sessionmaker(
bind=engine,
autocommit=False,
autoflush=False,
future=True
)
def get_db() -> Generator:
"""
Yield a synchronous SQLAlchemy session
Usage: Depends(get_db)
"""
db = SessionLocal()
try:
yield db
finally:
db.close()
# =========================
# ASYNCHRONOUS SESSION
# =========================
AsyncSessionLocal = sessionmaker(
bind=async_engine,
class_=AsyncSession,
expire_on_commit=False,
autocommit=False,
autoflush=False,
future=True
)
async def get_async_db() -> AsyncGenerator:
"""
Yield an asynchronous SQLAlchemy session
Usage: Depends(get_async_db)
"""
async with AsyncSessionLocal() as session:
yield session