Initial Switch to V2. Completely Overhauled Backend, Frontend and General Structure.
This commit is contained in:
16
backend/database/postgres.py
Normal file
16
backend/database/postgres.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
from config import settings
|
||||
|
||||
engine = create_async_engine(settings.database_url, pool_size=10, echo=False)
|
||||
AsyncSessionLocal = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
async def get_pg_session() -> AsyncSession:
|
||||
"""FastAPI dependency — yields a DB session and closes it after the request."""
|
||||
async with AsyncSessionLocal() as session:
|
||||
yield session
|
||||
Reference in New Issue
Block a user