Google App Engine 数据存储区中排序条目的放置
我想确定特定条目所在的位置,但我找不到相应的 GQL 查询。理想情况下,我想知道以下详细信息,这些细节似乎数据存储区应该知道。我似乎不知道如何确定它。有人可以帮忙吗?
- 特定条目的位置(在给定的排序中,即按特定属性)
- 存在的条目总数(不检索它们,只是计数)
- 列表中的下一个条目(我认为只要我能获得位置,我可以通过简单地获取 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 Python,请查看 google-app-engine-ranklist 项目,它在 App Engine 数据存储区中实现排名列表。
If you're using Python, check out the google-app-engine-ranklist project, which implements a rank list in the App Engine datastore.
GQL 非常有限,实际上只是为了让陷入 SQL 思维模式的人们更轻松地过渡到使用 App Engine 数据存储区。您无法使用 GQL 语法做任何您想做的事情。
假设您使用的是 python,第二个可以通过调用 db.Query 或 db.GqlQuery 对象的 .count() 方法来完成,但需要注意的是,您必须指定要计数的最大数量作为 count() 的参数,并且该最大值不能大于 1000。
如果不获取所有条目并进行查找,就无法在结果集中找到特定条目。然后,最后一个就变得微不足道了,因为您已经获取了所有实体,并且只需要获取下一个实体。
所有这些都不会有效;数据存储区不是为执行此类操作而设计的。
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.