Download database/connection.py from hrrbb/ruhi: direct link, hf CLI and curl.
- Browser
- Download file 820 Bytes
-
https://huggingface.co/spaces/hrrbb/ruhi/resolve/main/database/connection.py
- Command line
-
hf download hf://spaces/hrrbb/ruhi/database/connection.py
-
curl -L -o connection.py https://huggingface.co/spaces/hrrbb/ruhi/resolve/main/database/connection.py
820 Bytes
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from beanie import init_beanie | |
| from .schemas import QuranVerse, Hadith, Dua, Theme, Chapter, Section, HadithSahih, User | |
| from config import DB_NAME | |
| async def init_db(mongo_uri: str = None, db_name: str = None): | |
| """ | |
| Initializes MongoDB connection and configures Beanie ODM | |
| Args: | |
| mongo_uri: MongoDB connection string | |
| db_name: Database name to connect to | |
| Returns: | |
| AsyncIOMotorClient: Configured database client | |
| """ | |
| # Create MongoDB client | |
| client = AsyncIOMotorClient(mongo_uri) | |
| # Initialize Beanie with specific database | |
| await init_beanie( | |
| database=client[DB_NAME], | |
| document_models=[QuranVerse, Hadith, Dua, Theme, Chapter, Section, HadithSahih, User] | |
| ) | |
| return client |