refac: rework the variable times, mostly in ConnectionString

This commit is contained in:
Daan Selen
2025-09-23 09:08:21 +02:00
parent 8b541229d8
commit d8c89056cb
12 changed files with 41 additions and 41 deletions

View File

@@ -3,19 +3,19 @@ import configparser
import os
from sqlalchemy_utils import database_exists, create_database
# Ensure SQLite folder exists
SQLITE_PATH = "db"
os.makedirs(SQLITE_PATH, exist_ok=True)
DEFAULT_DB = "wgdashboard"
DEFAULT_LOG_DB = "wgdashboard_log"
DEFAULT_JOB_DB = "wgdashboard_job"
default_db = "wgdashboard"
default_log_db = "wgdashboard_log"
default_job_db = "wgdashboard_job"
sqlite_path = "db"
if os.path.exists(sqlite_path):
os.makedirs(sqlite_path, exist_ok=True)
def ConnectionString(database_name: str) -> str:
"""
Returns a SQLAlchemy-compatible connection string for the chosen database.
Creates the database if it doesn't exist.
"""
# Read and parse the INI file once at startup
parser = configparser.ConfigParser(strict=False)
parser.read("wg-dashboard.ini")
@@ -35,7 +35,7 @@ def ConnectionString(database_name: str) -> str:
host = parser.get("Database", "host")
cn = f"mysql+pymysql://{username}:{password}@{host}/{database_name}"
else:
cn = f'sqlite:///{os.path.join(sqlitePath, f"{database}.db")}'
cn = f'sqlite:///{os.path.join(sqlite_path, f"{database_name}.db")}'
try:
if not database_exists(cn):