File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/quant_research_starter/api Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ """Async database setup using SQLAlchemy for Postgres (asyncpg)."""
2+ from typing import AsyncGenerator
3+ import os
4+ from sqlalchemy .ext .asyncio import (
5+ create_async_engine ,
6+ AsyncSession ,
7+ async_sessionmaker ,
8+ )
9+ from sqlalchemy .orm import declarative_base
10+
11+ DATABASE_URL = os .getenv ("DATABASE_URL" , "postgresql+asyncpg://postgres:password@localhost:5432/qrs" )
12+
13+ engine = create_async_engine (DATABASE_URL , future = True , echo = False )
14+ AsyncSessionLocal = async_sessionmaker (engine , expire_on_commit = False , class_ = AsyncSession )
15+ Base = declarative_base ()
16+
17+
18+ async def get_session () -> AsyncGenerator [AsyncSession , None ]:
19+ async with AsyncSessionLocal () as session :
20+ yield session
You can’t perform that action at this time.
0 commit comments