Files
thePlug/app/core/mongodb.py
T
reloia a4d73efa77
Build and Push to Registry / build (push) Successful in 8s
chore: restructure project directory and update Dockerfile paths
2026-04-12 00:27:30 +02:00

24 lines
696 B
Python

from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
from core.config import settings
class _MongoDB:
client: AsyncIOMotorClient | None = None
def get_database(self) -> AsyncIOMotorDatabase:
if self.client is None:
raise RuntimeError("MongoDB client has not been initialized")
return self.client[settings.MONGODB_DB_NAME]
mongodb = _MongoDB()
async def get_database() -> AsyncIOMotorDatabase:
return mongodb.get_database()
async def ensure_mongodb_available() -> None:
client = mongodb.client
if client is None:
raise RuntimeError("MongoDB client has not been initialized")
await client.admin.command("ping")