@mytec: 1.1iter ready for testing
This commit is contained in:
0
backend/app/core/__init__.py
Normal file
0
backend/app/core/__init__.py
Normal file
BIN
backend/app/core/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
backend/app/core/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/core/__pycache__/config.cpython-311.pyc
Normal file
BIN
backend/app/core/__pycache__/config.cpython-311.pyc
Normal file
Binary file not shown.
BIN
backend/app/core/__pycache__/database.cpython-311.pyc
Normal file
BIN
backend/app/core/__pycache__/database.cpython-311.pyc
Normal file
Binary file not shown.
13
backend/app/core/config.py
Normal file
13
backend/app/core/config.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
MONGODB_URL: str = "mongodb://localhost:27017"
|
||||
DATABASE_NAME: str = "rfcp"
|
||||
TERRAIN_DATA_DIR: str = "/opt/rfcp/data/terrain"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
|
||||
settings = Settings()
|
||||
22
backend/app/core/database.py
Normal file
22
backend/app/core/database.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from motor.motor_asyncio import AsyncIOMotorClient
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
class Database:
|
||||
client: AsyncIOMotorClient = None
|
||||
|
||||
|
||||
db = Database()
|
||||
|
||||
|
||||
async def get_database():
|
||||
return db.client[settings.DATABASE_NAME]
|
||||
|
||||
|
||||
async def connect_to_mongo():
|
||||
db.client = AsyncIOMotorClient(settings.MONGODB_URL)
|
||||
|
||||
|
||||
async def close_mongo_connection():
|
||||
if db.client:
|
||||
db.client.close()
|
||||
Reference in New Issue
Block a user