Skip to content Skip to sidebar Skip to footer

How To Understand "cursor" Correctly

I'm trying to apply cursor to my app, however, the document is not clear enough for me. Google's description for cursor http://code.google.com/appengine/docs/python/datastore/quer

Solution 1:

Your understanding is more or less correct, but a cursor can't be thought of as simply adding filters. Supposing you have a result set ordered first by age, then by name. If your last returned result has age=30 and name=Bob, there's no set of criteria that will return exactly the results after that - age>=30 and name>Bob won't return Alice, who's 31.

A cursor is more like a bookmark into your result set. It denotes the place you left off, so you can come back later. If the result set is modified before or after your cursor, the cursor remains in the same place - so you'll always pick up where you left off.

To answer your other questions: Yes, queries always have an implied order. What that is depends on the query in question (in your case, it will be first by age, then by key), but it ensures there's a total order over the results. The paging article you refer to is out of date, and provides a pre-cursor approach to pagination. You can ignore it in favor of cursors.

You can pass cursors between tasks (and to and from users) just fine. If you're seeing an error, you'll have to show us the stacktrace before we can be of any help.

Post a Comment for "How To Understand "cursor" Correctly"