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