Skip to content

Instantly share code, notes, and snippets.

@berserker1
Last active August 22, 2019 10:36
Show Gist options
  • Save berserker1/6b214626042a6c976f780b33d2d12f32 to your computer and use it in GitHub Desktop.
Save berserker1/6b214626042a6c976f780b33d2d12f32 to your computer and use it in GitHub Desktop.
def dbconnection(function):
"""Decorator for getting at the database connection.
Use this to avoid having to access the global `config.db.store`
attribute. This calls the function with `store` as the first argument.
"""
def wrapper(*args, **kws):
# args[0] is self, if there is one.
if len(args) > 0:
return function(args[0], config.db.store, *args[1:], **kws)
else:
return function(config.db.store, **kws)
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment