Spaces:
Sleeping
Sleeping
Download database/connection.py from madhurithika22/Pouring: direct link, hf CLI and curl.
- Browser
- Download file 853 Bytes
-
https://huggingface.co/spaces/madhurithika22/Pouring/resolve/main/database/connection.py
- Command line
-
hf download hf://spaces/madhurithika22/Pouring/database/connection.py
-
curl -L -o connection.py https://huggingface.co/spaces/madhurithika22/Pouring/resolve/main/database/connection.py
853 Bytes
| from motor.motor_asyncio import AsyncIOMotorClient | |
| from core.config import settings | |
| class DatabaseClient: | |
| client: AsyncIOMotorClient = None | |
| def connect(self): | |
| try: | |
| # We configure a short connection timeout so that it fails fast and transparently | |
| # falls back to the file system if MongoDB is not available on localhost. | |
| self.client = AsyncIOMotorClient(settings.MONGO_URI, serverSelectionTimeoutMS=2000) | |
| print("MongoDB client initialized successfully.") | |
| except Exception as e: | |
| print(f"MongoDB initialization error: {e}") | |
| self.client = None | |
| def disconnect(self): | |
| if self.client: | |
| try: | |
| self.client.close() | |
| except Exception: | |
| pass | |
| self.client = None | |
| db_client = DatabaseClient() |