-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the session manager and use scoped_session
- Loading branch information
1 parent
7841559
commit 3106203
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker, scoped_session | ||
|
||
from common.constants import Constants | ||
|
||
|
||
class SessionManager(object): | ||
def __init__(self): | ||
self.engine = create_engine(Constants.DATABASE_URL) | ||
self.session_factory = sessionmaker(bind=self.engine) | ||
self.Session = scoped_session(self.session_factory) | ||
|
||
def get_icat_db_session(self): | ||
""" | ||
Gets a new session in the scoped_session collection | ||
:return: A new session | ||
""" | ||
|
||
return self.Session() | ||
|
||
|
||
session_manager = SessionManager() |