image_vector_search / db_session.py
kittchy
[ADD] image_vector_search
30099ac unverified
raw
history blame contribute delete
653 Bytes
import os
from pymongo import MongoClient
from pymongo.database import Database
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from dotenv import load_dotenv
load_dotenv(verbose=True)
USER_NAME = os.environ.get("DB_USERNAME")
PASSWORD = os.environ.get("DB_PASSWORD")
HOST = os.environ.get("DB_HOST")
MONGO_DATABASE_URL = f"mongodb+srv://{USER_NAME}:{PASSWORD}@{HOST}"
print(MONGO_DATABASE_URL)
client = MongoClient(MONGO_DATABASE_URL, server_api=ServerApi("1"))
def get_db() -> Database:
"""DB取得
Returns:
Database: データべース
"""
db: Database = client.db
return db