views:

26

answers:

2

I'd like to determine what place a particular entry is in, but the appropriate GQL query is escaping me. Ideally I'd like to know the following details, which seem like they should be known by the datastore. I just can't seem to figure how to determine it. Can someone help?

  • the placement of a particular entry (in a given sorting, i.e. by a particular property)
  • the total number of entries that exist (w/o retrieving them, just the count)
  • the next entry in the list (I figure as long as I can get the placement, I can make the right query to get the next one by simply getting 2 and taking the latter)

Can someone help?

A: 

GQL is very limited, and really only exists to give people stuck in an SQL mindset a slightly easier transition to using the App Engine datastore. You can't do any of the things you want to do with GQL syntax.

Assuming you're using python, the second can be done by calling the .count() method of a db.Query or db.GqlQuery object, with the caveat that you must specify the maximum number to count as the parameter to count(), and that this maximum cannot be larger than 1000.

You can't find a particular entry in the result set without fetching all of them and looking for it. The last then becomes trivial, since you've already been fetching all of the entities and you just need to fetch the next one.

None of this is going to be efficient; the datastore isn't designed to do this sort of stuff.

Wooble
Count is no longer limited to 1000.
Nick Johnson
+2  A: 

If you're using Python, check out the google-app-engine-ranklist project, which implements a rank list in the App Engine datastore.

Nick Johnson