Created
November 5, 2011 14:55
-
-
Save najeira/1341622 to your computer and use it in GitHub Desktop.
QueryIterator for async - Google App Engine / Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QueryIterator(object): | |
def __init__(self, query, limit=None): | |
self.limit = limit | |
self.count = 0 | |
if limit: | |
config = datastore_query.QueryOptions(limit=limit, prefetch_size=limit) | |
else: | |
config = None | |
self.iterator = query.run(config=config) | |
def __iter__(self): | |
return self | |
def next(self): | |
if self.limit and self.limit <= self.count: | |
raise StopIteration() | |
self.count += 1 | |
return self.iterator.next() | |
def get_result(self): | |
return [e for e in self] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment