Download app/database.py from jarnil/byteastra: direct link, hf CLI and curl.
- Browser
- Download file 671 Bytes
-
https://huggingface.co/spaces/jarnil/byteastra/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/jarnil/byteastra/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/jarnil/byteastra/resolve/main/app/database.py
671 Bytes
| """ | |
| ByteAstra backend — MongoDB database setup using PyMongo. | |
| """ | |
| from pymongo import MongoClient | |
| from app.config import get_settings | |
| settings = get_settings() | |
| client = MongoClient(settings.mongo_url) | |
| db = client.get_database("byteastra") | |
| def get_db(): | |
| """FastAPI dependency that provides a MongoDB database session.""" | |
| yield db | |
| def init_db(): | |
| """Configures indexes at startup.""" | |
| # Create indexes for high query performance | |
| db.sessions.create_index("user_id") | |
| db.sessions.create_index("updated_at") | |
| db.messages.create_index("session_id") | |
| db.messages.create_index("created_at") | |
| db.users.create_index("email", unique=True) | |