App Engine 数据存储区可以返回整个实体,也可以仅返回查询中的实体键?
我正在阅读 Google App Engine 文档,发现这一行难以理解
App Engine 数据存储区可以返回整个实体,也可以仅从查询中返回实体键。
这是什么意思?有 filter(property_operator, value)
和 fetch(limit, offset=0)
并且我相信 django-nonrel 在应用程序上支持 values()
引擎。那么这意味着什么呢?
I am reading Google App Engine doc and found this line difficult to understand
The App Engine datastore can either return entire entities or only entity keys from a query.
what does it mean? There is filter(property_operator, value)
and fetch(limit, offset=0)
And I believe django-nonrel support values()
on App Engine. So what does it mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行标准查询,如下所示:
这将返回实体列表(db.Model 实例)。或者,您可以执行仅键查询,如下所示:
它将仅返回匹配实体(db.Key 实例)的键,并且执行速度比第一个查询更快。
You can do a standard query, like this:
That will return a list of entities (db.Model instances). Or, you can do a keys-only query, like this:
That will return only the keys of the matching entities (db.Key instances), and is faster to execute than the first query.
这意味着,如果您只需要对象的键(可以找到该对象的唯一标识符)而不是其所有属性,则可以避免检索所有这些属性的额外开销。您可以使用keys_only参数来做到这一点。
例如,
SomeModel.all(keys_only=True).fetch(10)
将仅返回 SomeModel 实体的关键对象,而不是包含其属性的完整对象。
这可能会让您更多地了解键和完整对象之间的区别:
http://code.google.com/appengine/docs/python/datastore /entities.html
This means simply that if you only need the key for the object (the unique identifier by which it can be found) instead of all of its properties, you can avoid the additional overhead to retrieve all of these properties. You can do this by using the keys_only parameter.
For example,
SomeModel.all(keys_only=True).fetch(10)
will return just the key objects for the SomeModel entities instead of the full objects with their properties.
This may give you more of what you want to know about the difference between the keys and the full objects:
http://code.google.com/appengine/docs/python/datastore/entities.html