Skip to content

Commit

Permalink
Create SessionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Jul 29, 2019
1 parent 27a977c commit 0e7dfa4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
log = logging.getLogger()


class SessionManager(object):
_session = None

@staticmethod
def get_icat_db_session():
"""
Gets a session and connects with the ICAT database
:return: the session object
Checks if a session exists, if it does it returns the session if not a new one is created
:return: ICAT DB session
"""
log.info(" Getting ICAT DB session")
if SessionManager._session is None:
engine = create_engine(Constants.DATABASE_URL)
Session = sessionmaker(bind=engine)
session = Session()
return session
SessionManager._session = Session()
return SessionManager._session


class Query(ABC):
Expand Down

0 comments on commit 0e7dfa4

Please sign in to comment.