From: Jay Freeman (saurik) Date: Thu, 13 Jan 2011 06:03:34 +0000 (+0000) Subject: Replace pull/push with new __call__/set/all/one features. X-Git-Url: https://git.saurik.com/cyql.git/commitdiff_plain/38f04d60191229d45a16a851ec9dba366da59646?ds=sidebyside Replace pull/push with new __call__/set/all/one features. --- diff --git a/__init__.py b/__init__.py index 8ac73cf..dd150ae 100644 --- a/__init__.py +++ b/__init__.py @@ -60,6 +60,27 @@ class transaction(object): 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()