self.close()
raise
+ def transaction(self):
+ return Transaction(self)
+
class Row(dict):
"""A dict that allows for object-like property access syntax."""
raise AttributeError(name)
+class Transaction(object):
+ def __init__(self, db):
+ self.db = db
+
+ self.db.execute("START TRANSACTION")
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exctype, excvalue, traceback):
+ if exctype is not None:
+ self.db.execute("ROLLBACK")
+ else:
+ self.db.execute("COMMIT")
+
+
# Alias some common exceptions
IntegrityError = psycopg2.IntegrityError
OperationalError = psycopg2.OperationalError