From ce76f8fd2d2ff3bc81e258b3f5d7f9da9846827c Mon Sep 17 00:00:00 2001 From: Indigo Date: Thu, 8 Aug 2019 19:35:32 +0200 Subject: [PATCH] added session runner draft --- src/Controlers/SessionRunner.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/Controlers/SessionRunner.py diff --git a/src/Controlers/SessionRunner.py b/src/Controlers/SessionRunner.py new file mode 100644 index 0000000..825f449 --- /dev/null +++ b/src/Controlers/SessionRunner.py @@ -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) \ No newline at end of file