Commits

Guido Draheim committed 6d21447

introduce db.session.cnx(env)

Comments (0)

Files changed (3)

src/dvbcronrecording/db/db4.py

     modified = Column("modified", DateTime)
 
 metadata = RecordingModel.metadata
-tables = metadata.sorted_tables # support old aff() detection
 
 from tsab import engine
 

src/dvbcronrecording/db/schema.py

 
 import db4 
 
-tables = db4.tables
+metadata = db4.metadata
+tables = metadata.sorted_tables # support old aff() detection
 

src/dvbcronrecording/db/session.py

+from tsab import engine
+from schema import metadata
+from sqlalchemy.orm import create_session
+
+_session = None
+
+def context(env):
+    global _session
+    if _session is None:
+        _session = create_session(bind=engine(env))
+    return _session
+
+def cnx(env): return context(env)
+
+def commit():
+    global _session
+    if _session is not None:
+        _session.flush()
+
+def close():
+    global _session
+    if _session is not None:
+        _session.close()
+        _session = None
+