]> git.saurik.com Git - cyql.git/blobdiff - __init__.py
Handle exists() with format arguments.
[cyql.git] / __init__.py
index 2bddbe4a0afbf6dbb2fb3c6af948d938d670786d..10383d3c320ec5fe1f1c62c15e61adb753d789af 100644 (file)
@@ -56,8 +56,8 @@ class transaction(object):
         with self.connection.execute(statement, 1) as cursor:
             return cursor.fetchall()
 
-    def yank(self, statement):
-        with self.connection.execute(statement, 1) as cursor:
+    def yank(self, statement, offset=0):
+        with self.connection.execute(statement, 1 + offset) as cursor:
             rows = cursor.fetchall()
             return rows[0] if len(rows) != 0 else None
 
@@ -65,6 +65,13 @@ class transaction(object):
         with self.connection.execute(statement, 1) as cursor:
             pass
 
+    def exists(self, statement):
+        return self.yank('''
+            select exists (
+                {statement}
+            )
+        '''.format(**locals()), 1)[0]
+
 @contextmanager
 def connect(dsn):
     attempt = 0