Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Callable links can now return lists or tuples to the next query link.…
Browse files Browse the repository at this point in the history
… The list/tuple will be used as a parameter list for the query. If the query already has a parameter list and it is a 'list' then the list will be extended. If it's a tuple it will not be extended.
  • Loading branch information
FSX committed Apr 4, 2011
1 parent d44bf2b commit 5e4b99e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions examples/query_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ def get(self):
self._after_first_query,
self._after_first_callable,
['SELECT 1, 2, 3, 4, 5;'],
['SELECT 123, 132, 678;'],
self._before_last_query,
['SELECT %s, %s, %s, %s, %s;'],
self._on_response
])
qc.run()

def _after_first_query(self, cursor):
results = cursor.fetchall()
#return results[0]

return {
'p1': results[0][0],
'p2': results[0][1],
Expand All @@ -50,6 +49,10 @@ def _after_first_callable(self, p1, p2, p3, p4):
self.write('Results of the first query in the chain: %s, %s, %s, %s<br>' % \
(p1, p2, p3, p4))

def _before_last_query(self, cursor):
results = cursor.fetchall()
return [i*16 for i in results[0]]

def _on_response(self, cursor):
self.write('Results of the last query in the chain: %s' % \
cursor.fetchall())
Expand Down
5 changes: 4 additions & 1 deletion momoko/momoko.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,17 @@ def _collect(self, *args, **kwargs):
link = self._chain.popleft()
if callable(link):
results = link(*args, **kwargs)
print results
if type(results) is type([]) or type(results) is type(()):
self._collect(*results)
elif type(results) is type({}):
self._collect(**results)
else:
self._collect(results)
else:
if len(link) < 2:
link.append(args)
elif type(link[1]) is type([]):
link[1].extend(args)
self._db.execute(*link, callback=self._collect)

def run(self):
Expand Down

0 comments on commit 5e4b99e

Please sign in to comment.