]> git.saurik.com Git - cyql.git/commitdiff
Replace pull/push with new __call__/set/all/one features.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 13 Jan 2011 06:03:34 +0000 (06:03 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 13 Jan 2011 06:03:34 +0000 (06:03 +0000)
__init__.py

index 8ac73cf9320f1f978a071784770d1db836174eb3..dd150ae19ea6a64aed2b26103205267c773e21d0 100644 (file)
@@ -60,6 +60,27 @@ class transaction(object):
     def __init__(self, connection):
         self.connection = connection
 
     def __init__(self, connection):
         self.connection = connection
 
+    def __call__(self, statement, locals=None):
+        with self.connection.execute(statement, 1, locals) as cursor:
+            pass
+
+    @contextmanager
+    def set(self, statement):
+        with self.connection.execute(statement, 1) as cursor:
+            yield cursor
+
+    def all(self, statement):
+        with self.connection.execute(statement, 1) as cursor:
+            return cursor.fetchall()
+
+    def one(self, statement):
+        with self.connection.execute(statement, 1) as cursor:
+            one = cursor.fetchone()
+            if one == None:
+                return None
+            assert cursor.fetchone() == None
+            return one
+
     def pull(self, statement):
         with self.connection.execute(statement, 1) as cursor:
             return cursor.fetchall()
     def pull(self, statement):
         with self.connection.execute(statement, 1) as cursor:
             return cursor.fetchall()