keepme-backend / src /config /_database.py
ramanjitsingh1368's picture
code refactor
eb474ee
raw
history blame contribute delete
782 Bytes
import os
from beanie import init_beanie
from motor.motor_asyncio import AsyncIOMotorClient
from src.models import User, Session, File, VectorStoreRecordId, Conversation, Message
class DatabaseConfig:
def __init__(self):
self.MONGO_URI = os.getenv("MONGO_DB_URI")
self.MONGO_DB_NAME = os.getenv("MONGO_DB_NAME")
self.client = AsyncIOMotorClient(self.MONGO_URI, uuidRepresentation="standard")
self.db = self.client[self.MONGO_DB_NAME]
async def init_beanie(self):
await init_beanie(
database=self.db,
document_models=[
User,
Session,
Conversation,
Message,
File,
VectorStoreRecordId,
],
)