refactor(database): configurable database source

This commit is contained in:
2026-03-29 21:30:18 +01:00
parent f996b38fa5
commit e776ef53ac
2 changed files with 15 additions and 6 deletions

2
.gitignore vendored
View File

@@ -11,5 +11,5 @@ node_modules/
dist/
helper
db
report/build

View File

@@ -1,8 +1,17 @@
import os
import psycopg2
import os
from dotenv import load_dotenv
from psycopg2.extras import RealDictCursor
from psycopg2.extras import execute_batch
load_dotenv()
postgres_host = os.getenv("POSTGRES_HOST", "localhost")
postgres_port = os.getenv("POSTGRES_PORT", 5432)
postgres_user = os.getenv("POSTGRES_USER", "postgres")
postgres_password = os.getenv("POSTGRES_PASSWORD", "postgres")
postgres_db = os.getenv("POSTGRES_DB", "postgres")
from server.exceptions import DatabaseNotConfiguredException
@@ -15,11 +24,11 @@ class PostgresConnector:
try:
self.connection = psycopg2.connect(
host=os.getenv("POSTGRES_HOST", "localhost"),
port=os.getenv("POSTGRES_PORT", 5432),
user=os.getenv("POSTGRES_USER", "postgres"),
password=os.getenv("POSTGRES_PASSWORD", "postgres"),
database=os.getenv("POSTGRES_DB", "postgres"),
host=postgres_host,
port=postgres_port,
user=postgres_user,
password=postgres_password,
database=postgres_db,
)
except psycopg2.OperationalError as e:
raise DatabaseNotConfiguredException(