H4CK3R-01
43ee84912e
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
27 lines
816 B
Python
27 lines
816 B
Python
from beanie import init_beanie
|
|
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from pydantic import BaseSettings, Field
|
|
import re
|
|
|
|
from models.request import Request
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
DATABASE_URL: str = Field(..., env="DATABASE_URL")
|
|
AZURE_KEY: str = Field(..., env="AZURE_KEY")
|
|
AZURE_ENDPOINT: str = Field(..., env="AZURE_ENDPOINT")
|
|
AZURE_LOCATION: str = Field(..., env="AZURE_LOCATION")
|
|
ENV: str = Field(..., env="ENV")
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
orm_mode = True
|
|
|
|
|
|
async def initiate_database():
|
|
parts = Settings().DATABASE_URL.split("/?")
|
|
db_url_with_database = parts[0] + "/requests?" + parts[1]
|
|
|
|
client = AsyncIOMotorClient(db_url_with_database)
|
|
await init_beanie(database=client.get_default_database(), document_models=[Request])
|