From 7b9d4a4f8b9f21967c9354acd8636893a6dd62b9 Mon Sep 17 00:00:00 2001 From: devsjc <47188100+devsjc@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:18:49 +0000 Subject: [PATCH] Single DatabaseConnection passed to sessions (#312) --- src/database.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/database.py b/src/database.py index fe73eb2..55b7bdf 100644 --- a/src/database.py +++ b/src/database.py @@ -42,6 +42,9 @@ ) from utils import filter_forecast_values, floor_30_minutes_dt, get_start_datetime +db_conn = DatabaseConnection(url=os.getenv("DB_URL", "not_set")) +pv_db_conn = DatabaseConnection(url=os.getenv("DB_URL_PV", "not_set")) + logger = structlog.stdlib.get_logger() # merged from @@ -257,17 +260,15 @@ def get_latest_forecast_values_for_a_specific_gsp_from_database( def get_session(): """Get database settion""" - connection = DatabaseConnection(url=os.getenv("DB_URL", "not_set")) - with connection.get_session() as s: + with db_conn.get_session() as s: yield s def get_session_pv(): """Get database sessions to pv database""" - connection = DatabaseConnection(url=os.getenv("DB_URL_PV", "not_set")) - with connection.get_session() as s: + with pv_db_conn.get_session() as s: yield s