Class QueryIterator
Converts a database query into a result iterator
from __future__ import generators
from twisted.enterprise import adbapi
from twisted.internet import reactor
from twisted.flow import flow
from twisted.flow.threads import QueryIterator, Threaded
dbpool = adbapi.ConnectionPool("SomeDriver",host='localhost',
db='Database',user='User',passwd='Password')
# # I test with...
# from pyPgSQL import PgSQL
# dbpool = PgSQL
sql = '''
(SELECT 'one')
UNION ALL
(SELECT 'two')
UNION ALL
(SELECT 'three')
'''
def consumer():
print "executing"
query = Threaded(QueryIterator(dbpool, sql))
print "yielding"
yield query
print "done yeilding"
for row in query:
print "Processed result : ", row
yield query
from twisted.internet import reactor
def finish(result):
print "Deferred Complete : ", result
reactor.stop()
f = flow.Deferred(consumer())
f.addBoth(finish)
reactor.run()
Method Summary |
|
__init__(self,
pool,
sql,
fetchmany,
fetchall)
|
|
__iter__(self)
|
|
next(self)
|
|
next_fetchall(self)
|
|
next_fetchmany(self)
|