]> git.saurik.com Git - cyql.git/commitdiff
Add @cyql.connected() decorator to make functions that operate with database connecti...
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 12 May 2010 12:53:22 +0000 (12:53 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 12 May 2010 12:53:22 +0000 (12:53 +0000)
__init__.py

index 0c29a582215770b31c8ed2cffdc820e5fa49c525..0f11db4e73652355bfcfe9684e669ac847598fea 100644 (file)
@@ -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: