Created
October 1, 2012 15:56
-
-
Save andylolz/3812667 to your computer and use it in GitHub Desktop.
Useful useful useful
This file contains hidden or 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
| def fetch_all(model_or_query): | |
| '''Fetch all the entities of the given model, or satisfying the given query. | |
| ''' | |
| if isinstance(model_or_query, type) and issubclass(model_or_query, db.Model): | |
| query = model_or_query.all(keys_only=False) | |
| elif isinstance(model_or_query, db.Query): | |
| query = model_or_query | |
| else: | |
| raise Exception("model_or_query is neither a model nor a query") | |
| results = [] | |
| while True: | |
| to_fetch = query.fetch(500) | |
| results += to_fetch | |
| if len(to_fetch) < 500: | |
| return results | |
| query.with_cursor(query.cursor()) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fetch all donations:
Fetch all donations for school $school: