From 91d72c6c38f38909f6e86d70a622c7625b4c9462 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 12 May 2010 12:53:22 +0000 Subject: [PATCH] Add @cyql.connected() decorator to make functions that operate with database connections simpler to deploy. --- __init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/__init__.py b/__init__.py index 0c29a58..0f11db4 100644 --- a/__init__.py +++ b/__init__.py @@ -80,6 +80,14 @@ def connect(dsn): finally: driver.close() +def connected(dsn): + def wrapped(method): + def replaced(*args, **kw): + with connect(dsn) as connection: + return method(connection, *args, **kw) + return replaced + return wrapped + @contextmanager def transact(dsn, **args): with connect(dsn) as connection: -- 2.47.2