mirror of
https://github.com/creyD/creyPY.git
synced 2026-04-13 03:40:31 +02:00
24 lines
607 B
Python
24 lines
607 B
Python
from typing import AsyncGenerator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from .common import SQLALCHEMY_DATABASE_URL, name
|
|
|
|
async_engine = create_async_engine(
|
|
SQLALCHEMY_DATABASE_URL + name, pool_pre_ping=True, connect_args={"sslmode": "require"}
|
|
)
|
|
|
|
AsyncSessionLocal = sessionmaker(
|
|
bind=async_engine,
|
|
class_=AsyncSession,
|
|
expire_on_commit=False,
|
|
autoflush=False,
|
|
autocommit=False,
|
|
)
|
|
|
|
|
|
async def get_async_db() -> AsyncGenerator[AsyncSession, None]:
|
|
async with AsyncSessionLocal() as db:
|
|
yield db
|