开发者

The App Engine datastore can either return entire entities or only entity keys from a query?

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开发者_如何学Go. So what does it mean?


You can do a standard query, like this:

results = MyModel.all().filter('foo =', 'bar').fetch(20)

That will return a list of entities (db.Model instances). Or, you can do a keys-only query, like this:

results = MyModel.all(keys_only=True).filter('foo =', 'bar').fetch(20)

That will return only the keys of the matching entities (db.Key instances), and is faster to execute than the first query.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜