http://imapfw.offlineimap.org IMAP/mail framework under MIT licence and written in Python
#
# storage
#
@di.provides(scope="PER_ROOT")
def transaction():
return Transaction()
@di.provides(scope="GLOBAL")
def storage__sqlite_instance(configuration):
return SQLiteInstance.create_or_open(configuration.storage_root_path_sqlite)
@di.provides(scope="PER_ROOT")
def storage__DB(storage__sqlite_instance, transaction):
return SQliteTX(storage__sqlite_instance, transaction)
The idea is that you normally operate in some kind of business transaction or context.
At the beginning of such a transaction (say the request handler for a REST call) you would create a new business transaction (I named it query root
):
query_root = di.new_query_root()
db = query_root.get_dependency(“storage__DB”)