Skip to content

Instantly share code, notes, and snippets.

@justdoit0823
justdoit0823 / sqlalchemy_session.py
Last active January 25, 2023 15:50
A simple sqlalchemy session decorator and context manager for db operation function.
session_engines = {}
def get_new_session(connection=None, autocommit=None):
connection = connection or 'default'
connection_settings = settings.DATABASES[connection]
connection_autocommit = ValueUtils.none_or(
connection_settings.get('autocommit'), False)
autocommit = ValueUtils.none_or(autocommit, connection_autocommit)