python - how to understand "cursor" correctly -
i'm trying apply cursor app, however, document not clear enough me. google's description cursor http://code.google.com/appengine/docs/python/datastore/queries.html#query_cursors
the cursor's position defined location in result list after last result returned. cursor not relative position in list (it's not offset); it's marker datastore can jump when starting index scan results. if results query change between uses of cursor, query notices changes occur in results after cursor. if new result appears before cursor's position query, not returned when results after cursor fetched. similarly, if entity no longer result query had appeared before cursor, results appear after cursor not change. if last result returned removed result set, cursor still knows how locate next result.
in understanding, looks query results return default order (such __ key __). then, specify cursor, add filter filter out results before cursor. google has mentioned in past. true?
paging __ key __ , non-unique property http://code.google.com/appengine/articles/paging.html
another question, can cursor used iteration or task? reasons, function won't work correctly. may generate "query not found" in iteration process.
this example:
people = person.all().filter("age > ", 30) if cursor: people.with_cursor(cursor) try: person in people: # query not found cursor = people.cursor() except deadlineexceedederror: taskqueue.add(url="/people", params= {"cursor", cursor})
your understanding more or less correct, cursor can't thought of adding filters. supposing have result set ordered first age, name. if last returned result has age=30 , name=bob, there's no set of criteria return results after - age>=30 , name>bob won't return alice, who's 31.
a cursor more bookmark result set. denotes place left off, can come later. if result set modified before or after cursor, cursor remains in same place - you'll pick left off.
to answer other questions: yes, queries have implied order. depends on query in question (in case, first age, key), ensures there's total order on results. paging article refer out of date, , provides pre-cursor approach pagination. can ignore in favor of cursors.
you can pass cursors between tasks (and , users) fine. if you're seeing error, you'll have show stacktrace before can of help.
Comments
Post a Comment