LBHB / NEMS0

THIS VERSION OF NEMS IS NO LONGER SUPPORTED. PLEASE USE THE NEW NEMS REPOSITORY OR INSTALL NEMS_DB TO GET NEMS0 SUPPORT.
GNU General Public License v3.0
8 stars 4 forks source link

Migrate SQL queries to SQLAlchemy for compat between sqlite and mysql #202

Open arrrobase opened 4 years ago

arrrobase commented 4 years ago

Also need to add a context manager to close connections after queries. Something like this:

from nems.db import Session

@contextmanager
def db_session():
    session = Session()
    try:
        yield session
        session.commit()
    except:
         session.rollback()
    finally:
         session.close()

with db_session() as session:
    session.add(object)

https://docs.sqlalchemy.org/en/13/orm/session_basics.html