Some checks are pending
Create and publish a Docker image / build-and-push-image (push) Waiting to run
22 lines
745 B
Python
22 lines
745 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
import os
|
|
|
|
import config
|
|
|
|
if config.DB_ENGINE == "mysql":
|
|
database_url = f"mysql+pymysql://{config.DB_USER}:{config.DB_PASSWORD}@{config.DB_HOST}:{config.DB_PORT}/{config.DB_NAME}"
|
|
|
|
elif config.DB_ENGINE == "postgresql":
|
|
database_url = f"postgresql+psycopg2://{config.DB_USER}:{config.DB_PASSWORD}@{config.DB_HOST}:{config.DB_PORT}/{config.DB_NAME}"
|
|
|
|
else:
|
|
if not os.path.exists("data"):
|
|
os.makedirs("data")
|
|
database_url = "sqlite:///data/data.db"
|
|
|
|
engine = create_engine(database_url)
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
Base = declarative_base()
|