-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagers.py
More file actions
32 lines (24 loc) · 744 Bytes
/
managers.py
File metadata and controls
32 lines (24 loc) · 744 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
import fdb
import flask
from models import BasicModel
from sqlbuilder import SQLSelect
def get_db():
"""Opens a new database connection if there is none yet for the
current application context.
"""
if not hasattr(flask.g, 'fb_db'):
flask.g.fb_db = fdb.connect(
dsn='db/TIMETABLE.FDB',
user='SYSDBA',
password='masterkey',
connection_class=fdb.ConnectionWithSchema,
charset='UTF8'
)
return flask.g.fb_db
def close_db(error):
"""Closes the database again at the end of the request."""
if hasattr(flask.g, 'fb_db'):
flask.g.fb_db.close()
class BaseManager:
def __init__(self, model: BasicModel):
self.model = model