Skip to content

Commit

Permalink
Merge pull request #132 from openclimatefix/issue/one-connection
Browse files Browse the repository at this point in the history
only open one session
  • Loading branch information
peterdudfield authored Dec 1, 2023
2 parents 320194c + 5d6e20c commit 982bb8e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pv_site_api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

from pvsite_datamodel.connection import DatabaseConnection

try:
connection = DatabaseConnection(url=os.getenv("DB_URL", "not_set"))
except Exception as e:
print(e)
print("Could not connect to database")


def get_session():
"""Get database settion"""
if int(os.environ.get("FAKE", 0)):
yield None
else:
connection = DatabaseConnection(url=os.getenv("DB_URL", "not_set"))

with connection.get_session() as s:
yield s

0 comments on commit 982bb8e

Please sign in to comment.