added session runner draft

This commit is contained in:
Indigo 2019-08-08 19:35:32 +02:00
parent 42628c110a
commit ce76f8fd2d
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
### another way (but again *not the only way*) to do it ###
from contextlib import contextmanager
@contextmanager
def session_scope():
"""Provide a transactional scope around a series of operations."""
session = Session()
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
session.close()
#all session.add will be done in session_scope(). tbd: remove individual commits from ORM_test.py
def run_my_program():
with session_scope() as session:
#ThingOne().go(session)
#ThingTwo().go(session)