def transaction(self,implicit = False):
        """
        This returns a context guard which will automatically open and close a transaction
        """

        class TransactionManager(object):

            def __init__(self,backend,implicit = False):
                self.backend = backend
                self.implicit =  implicit

            def __enter__(self):
                self.within_transaction = True if self.backend.current_transaction else False
                self.transaction = self.backend.begin()

            def __exit__(self,exc_type,exc_value,traceback_obj):
                if exc_type:
                    self.backend.rollback(self.transaction)
                    return False
                else:
                    #if the transaction has been created implicitly and we are not within
                    #another transaction, we leave it open (the user needs to call commit manually)
                    #if self.implicit and not self.within_transaction:
                    #    return
                    self.backend.commit(self.transaction)

        return TransactionManager(self,implicit = implicit)
This returns a context guard which will automatically open and close a transaction