Skip to content

Commit

Permalink
Single DatabaseConnection passed to sessions (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsjc authored Dec 1, 2023
1 parent de293c0 commit 7b9d4a4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 7b9d4a4

Please sign in to comment.