first commit
This commit is contained in:
commit
cce9a8c9ba
73 changed files with 8665 additions and 0 deletions
27
backend/app/database.py
Normal file
27
backend/app/database.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue