crappy
This commit is contained in:
19
backend/session.py
Normal file
19
backend/session.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from .config import PG_DATABASE, PG_HOST, PG_PASSWORD, PG_LOGIN
|
||||
|
||||
DATABASE_URL = f'postgresql+asyncpg://{PG_LOGIN}:{PG_PASSWORD}@{PG_HOST}/{PG_DATABASE}'
|
||||
engine = create_async_engine(DATABASE_URL)
|
||||
session_maker = sessionmaker(
|
||||
engine,
|
||||
class_=AsyncSession,
|
||||
expire_on_commit=False,
|
||||
autocommit=False,
|
||||
autoflush=False
|
||||
)
|
||||
|
||||
|
||||
async def get_session() -> AsyncSession:
|
||||
async with session_maker() as session:
|
||||
yield session
|
||||
Reference in New Issue
Block a user