-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabaseManager.py
More file actions
33 lines (22 loc) · 797 Bytes
/
databaseManager.py
File metadata and controls
33 lines (22 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy import create_engine
from database import Base
import tbl_user # noqa pylint: disable=unused-import
class DatabaseManager:
"""
Pseudo database manager for SQLAlchemy
"""
def __init__(self, engine=None):
if not engine:
my_engine = create_engine('sqlite:///mydb.sqlite', echo=False)
Base.metadata.create_all(my_engine)
self.engine = my_engine
else:
self.engine = engine
session_factory = sessionmaker(bind=self.engine)
self.session_cls = scoped_session(session_factory)
def open_session(self):
return self.session_cls()
def close_session(self):
self.session_cls.remove()
dbm = DatabaseManager()