first commit

This commit is contained in:
Anurag Jangid 2026-10-08 02:41:41 +05:30
commit d416fe4cce
69 changed files with 8269 additions and 0 deletions

View file

29
backend/app/db/mongo.py Normal file
View file

@ -0,0 +1,29 @@
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
from app.core.config import settings
client: AsyncIOMotorClient | None = None
def get_database() -> AsyncIOMotorDatabase:
if client is None:
raise RuntimeError("MongoDB client has not been initialized")
return client[settings.mongo_db_name]
def get_client() -> AsyncIOMotorClient:
if client is None:
raise RuntimeError("MongoDB client has not been initialized")
return client
async def connect_to_mongo() -> None:
global client
client = AsyncIOMotorClient(settings.mongo_uri)
async def close_mongo_connection() -> None:
global client
if client is not None:
client.close()
client = None