]> git.saurik.com Git - cyql.git/blobdiff - __init__.py
Switch to psycopg2 autocommit syntax.
[cyql.git] / __init__.py
index 9dc57b361c695ce098736d5582c0d00a47c0da13..9fc8d31c388bea89919ee55c414d99311c962b24 100644 (file)
@@ -31,13 +31,13 @@ class connect(object):
 
         try:
             self.driver.set_client_encoding('UNICODE')
-            self.driver.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
+            self.driver.autocommit = True
         except:
             self.driver.close()
 
         try:
             psycopg2.extras.register_hstore(self.driver, globally=False, unicode=True)
-        except ProgrammingError, e:
+        except psycopg2.ProgrammingError, e:
             pass
 
     def close(self):
@@ -49,6 +49,15 @@ class connect(object):
     def __exit__(self, type, value, traceback):
         self.close()
 
+    def begin(self):
+        self.driver.autocommit = False
+
+    def commit(self):
+        self.driver.commit()
+
+    def rollback(self):
+        self.driver.rollback()
+
     @contextmanager
     def cursor(self):
         cursor = self.driver.cursor(cursor_factory=psycopg2.extras.DictCursor)
@@ -108,7 +117,7 @@ class connect(object):
 
     @contextmanager
     def transact(self, synchronous_commit=True):
-        self.driver.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_READ_COMMITTED)
+        self.driver.autocommit = False
         try:
             with self.cursor() as cursor:
                 if not synchronous_commit:
@@ -120,7 +129,7 @@ class connect(object):
             self.driver.rollback()
             raise
         finally:
-            self.driver.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
+            self.driver.autocommit = True
 
     def one_(self, statement, context=None):
         with self.execute(statement, 2, context) as cursor:
@@ -144,8 +153,8 @@ class connect(object):
         with self.execute(statement, 1) as cursor:
             yield cursor
 
-    def all(self, statement):
-        with self.execute(statement, 1) as cursor:
+    def all(self, statement, context=None):
+        with self.execute(statement, 1, context) as cursor:
             return cursor.fetchall()
 
     def one(self, statement, context=None):