refactor(database): configurable database source
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -11,5 +11,5 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
|
|
||||||
helper
|
helper
|
||||||
|
db
|
||||||
report/build
|
report/build
|
||||||
@@ -1,8 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
from psycopg2.extras import RealDictCursor
|
from psycopg2.extras import RealDictCursor
|
||||||
from psycopg2.extras import execute_batch
|
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
|
from server.exceptions import DatabaseNotConfiguredException
|
||||||
|
|
||||||
|
|
||||||
@@ -15,11 +24,11 @@ class PostgresConnector:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.connection = psycopg2.connect(
|
self.connection = psycopg2.connect(
|
||||||
host=os.getenv("POSTGRES_HOST", "localhost"),
|
host=postgres_host,
|
||||||
port=os.getenv("POSTGRES_PORT", 5432),
|
port=postgres_port,
|
||||||
user=os.getenv("POSTGRES_USER", "postgres"),
|
user=postgres_user,
|
||||||
password=os.getenv("POSTGRES_PASSWORD", "postgres"),
|
password=postgres_password,
|
||||||
database=os.getenv("POSTGRES_DB", "postgres"),
|
database=postgres_db,
|
||||||
)
|
)
|
||||||
except psycopg2.OperationalError as e:
|
except psycopg2.OperationalError as e:
|
||||||
raise DatabaseNotConfiguredException(
|
raise DatabaseNotConfiguredException(
|
||||||
|
|||||||
Reference in New Issue
Block a user