-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
27 lines (21 loc) · 721 Bytes
/
database.py
File metadata and controls
27 lines (21 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pymongo import MongoClient
from pymongo.database import Database
import os
from typing import Generator
# Database configuration
MONGODB_URI = os.getenv("MONGODB_URI", "mongodb://localhost:27017/")
DATABASE_NAME = os.getenv("DATABASE_NAME", "voice_assistant")
# Create MongoDB client
client = MongoClient(MONGODB_URI)
database = client[DATABASE_NAME]
def init_db():
"""Initialize database - create indexes if needed"""
# Create index on client id
database.clients.create_index("clientId", unique=True)
print(f"Connected to MongoDB: {DATABASE_NAME}")
def get_db() -> Generator[Database, None, None]:
"""Dependency to get database"""
try:
yield database
finally:
pass