Skip to content

Commit

Permalink
#48: Allow use of with keyword with Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Sep 19, 2019
1 parent 40a3463 commit ee9265a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def __init__(self, table):
self.table = table
self.base_query = self.session.query(table)

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
log.info("Closing DB session")
self.session.close()

@abstractmethod
def execute_query(self):
pass
Expand Down

0 comments on commit ee9265a

Please sign in to comment.