test
This commit is contained in:
24
backend/session.py
Normal file
24
backend/session.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from typing import AsyncGenerator
|
||||
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker, AsyncSession
|
||||
|
||||
from .config import (
|
||||
PG_HOST,
|
||||
PG_LOGIN,
|
||||
PG_PORT,
|
||||
PG_DATABASE,
|
||||
PG_PASSWORD,
|
||||
)
|
||||
|
||||
database_url = (
|
||||
f"postgresql+asyncpg://"
|
||||
f"{PG_LOGIN}:{PG_PASSWORD}@"
|
||||
f"{PG_HOST}:{PG_PORT}/{PG_DATABASE}"
|
||||
)
|
||||
engine = create_async_engine(database_url)
|
||||
session_factory = async_sessionmaker(engine, expire_on_commit=False, autoflush=False, autocommit=False)
|
||||
|
||||
|
||||
async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
async with session_factory() as session:
|
||||
yield session
|
||||
Reference in New Issue
Block a user