about summary refs log tree commit diff
path: root/wqflask/db/call.py
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask/db/call.py')
-rw-r--r--wqflask/db/call.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/wqflask/db/call.py b/wqflask/db/call.py
index 6b15abb3..ba6eb149 100644
--- a/wqflask/db/call.py
+++ b/wqflask/db/call.py
@@ -15,6 +15,21 @@ logger = getLogger(__name__ )
 
 from inspect import stack
 
+def fetch1(query, path=None, func=None):
+    """Fetch one result using either a SQL query or the URI path to
+GN_SERVER (when USE_GN_SERVER is True). Apply func to GN_SERVER result
+when set.
+
+    """
+    if USE_GN_SERVER and path:
+        result = gn_server(path)
+        if func != None:
+            return [func(result)]
+        else:
+            return [result]
+    else:
+        return fetchone(query)
+
 def fetchone(query):
     """Return tuple containing one row by calling SQL directly
 
@@ -23,7 +38,7 @@ def fetchone(query):
         def helper(query):
             res = g.db.execute(query)
             return res.fetchone()
-        callername = stack()[1][3]
+        callername = stack()[2][3]
         return logger.sql(callername, query, helper)
 
 def gn_server(path):