From 38f04d60191229d45a16a851ec9dba366da59646 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 13 Jan 2011 06:03:34 +0000 Subject: [PATCH] Replace pull/push with new __call__/set/all/one features. --- __init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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() -- 2.45.2