27 lines
692 B
Python
27 lines
692 B
Python
from collections.abc import AsyncIterator
|
|
|
|
from pymongo import AsyncMongoClient
|
|
from sqlalchemy.ext.asyncio import (
|
|
AsyncSession,
|
|
async_sessionmaker,
|
|
create_async_engine,
|
|
)
|
|
|
|
from app.config import get_settings
|
|
|
|
settings = get_settings()
|
|
|
|
engine = create_async_engine(settings.database_url, pool_pre_ping=True)
|
|
SessionFactory = async_sessionmaker(engine, expire_on_commit=False)
|
|
|
|
mongo_client: AsyncMongoClient = AsyncMongoClient(settings.mongo_url)
|
|
mongo_db = mongo_client[settings.mongo_database]
|
|
|
|
|
|
async def get_postgres_session() -> AsyncIterator[AsyncSession]:
|
|
async with SessionFactory() as session:
|
|
yield session
|
|
|
|
|
|
def get_mongo_database():
|
|
return mongo_db
|