mirror of
https://github.com/Sosokker/HomieCare.git
synced 2025-12-19 02:04:03 +01:00
Add database connection file and config file
This commit is contained in:
parent
b677084100
commit
ba5c11d61b
@ -0,0 +1,24 @@
|
||||
"""
|
||||
This file is used to store the configuration of the project.
|
||||
|
||||
Attributes:
|
||||
DB_HOST: The host of the MySQL database
|
||||
DB_USER: The username of the MySQL database
|
||||
DB_PASSWD: The password of the MySQL database
|
||||
DB_NAME: The name of the MySQL database
|
||||
MINIO_ENDPOINT: The endpoint of the MinIO storage
|
||||
MINIO_ACCESS_KEY: The access key of the MinIO storage
|
||||
MINIO_SECRET_KEY: The secret key of the MinIO storage
|
||||
"""
|
||||
|
||||
from decouple import Config, Csv
|
||||
|
||||
config = Config('.env')
|
||||
|
||||
DB_HOST = config.get('DB_HOST')
|
||||
DB_USER = config.get('DB_USER')
|
||||
DB_PASSWD = config.get('DB_PASSWD')
|
||||
DB_NAME = config.get('DB_NAME')
|
||||
MINIO_ENDPOINT = config.get('MINIO_ENDPOINT')
|
||||
MINIO_ACCESS_KEY = config.get('MINIO_ACCESS_KEY')
|
||||
MINIO_SECRET_KEY = config.get('MINIO_SECRET_KEY')
|
||||
@ -0,0 +1,30 @@
|
||||
"""
|
||||
Database Configuration and Connection Setup
|
||||
|
||||
This file contains the configuration and setup for connecting to the database using SQLAlchemy and MinIO.
|
||||
|
||||
Attributes:
|
||||
engine: SQLAlchemy engine for database connection.
|
||||
SessionLocal: SQLAlchemy session maker for database sessions.
|
||||
Base: SQLAlchemy base class for declarative ORM models.
|
||||
minio_client: MinIO client for interacting with MinIO storage.
|
||||
"""
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from minio import Minio
|
||||
from config import DB_HOST, DB_USER, DB_PASSWD, DB_NAME, MINIO_ENDPOINT, MINIO_ACCESS_KEY, MINIO_SECRET_KEY
|
||||
|
||||
engine = create_engine(f"mysql+pymysql://{DB_USER}:{DB_PASSWD}@{DB_HOST}/{DB_NAME}")
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
Base = declarative_base()
|
||||
|
||||
USE_SSL = False
|
||||
minio_client = Minio(
|
||||
endpoint=MINIO_ENDPOINT,
|
||||
access_key=MINIO_ACCESS_KEY,
|
||||
secret_key=MINIO_SECRET_KEY,
|
||||
secure=USE_SSL
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user