[英]Querying selected fields in an entity in objectify - appengine
I am using appengine and objectify as a backend for my app. 我正在使用appengine和objectify作为我的应用程序的后端。 And when i query in the datastore i get a Entity object which has the data of required row.
当我在数据存储区中查询时,我得到一个实体对象,该对象具有所需行的数据。 But, using objectify how will i query entities and get oly selected fileds from it?
但是,使用objectify我将如何查询实体并从中获取全部选定的文件? because querying the whole entity will be heavy and it needs more data bandwidth.
因为查询整个实体会很麻烦,并且需要更多的数据带宽。
Eg : In a entity with 4 columns, --> Id,name,description,age. 例如:在具有4列的实体中,-> ID,名称,描述,年龄。 I should query oly Id,name,age.
我应该查询身份证号,姓名,年龄。 I dont want description to be queried.
我不希望查询描述。
The GAE datastore does not work like an RDBMS; GAE数据存储无法像RDBMS那样工作; you can't arbitrarily pick and choose which fields to query out of an entity.
您不能随意选择要从实体中查询的字段。 The standard behavior of a datastore query is to follow an index (which maps attribute value to entity key), then fetch-by-key all the entities found.
数据存储区查询的标准行为是遵循索引(将属性值映射到实体键),然后按键获取所有找到的实体。
There is a feature called "projection queries" (which Objectify supports; look for the project()
method on the query command object), however it is not a general purpose SELECT statement like you get in SQL. 有一个称为“投影查询”的功能(Objectify支持;在查询命令对象上查找
project()
方法),但是它不是像SQL中那样的通用SELECT语句。 Projection queries capitalize on the fact that the index itself contains the index values, so if you only want data that's in the index, you don't need to perform a subsequent fetch of the whole Entity. 投影查询充分利用了索引本身包含索引值的事实,因此,如果您只希望索引中的数据,则无需随后对整个Entity进行提取。 However, this comes with some restrictions:
但是,这有一些限制:
Be aware of the cost of using projection queries. 注意使用投影查询的成本。 In your example, you will need single-property indexes on Name and Age plus a multiproperty index on
{__key__, Name, Age}
. 在您的示例中,您将需要在Name和Age上使用单属性索引,并在
{__key__, Name, Age}
上使用多属性索引。 Instead of 3 write operations per entity written, your new entity will cost 8 write ops. 您的新实体将花费8个写入操作,而不是每个写入的实体进行3个写入操作。 On the other hand, the cost of a projection query is a constant 1 read op.
另一方面,投影查询的成本是恒定的1次读取操作。
On the other other hand, the cost of a batch get from memcache is 0, and the worst-case cost is 1 read op. 而另一方面,一个批次的成本从内存缓存得到的是0,最坏情况下的成本为1读取运算。 Unless your description field is known to be causing you problems, this is a massive premature optimization.
除非您知道您的描述字段会引起问题,否则这是一个过早的优化。
If you are looking for projection queries, they are not yet implemented in Objectify. 如果您正在寻找投影查询,则它们尚未在Objectify中实现。
https://groups.google.com/forum/#!topic/objectify-appengine/uvLIHhHMEM0 https://groups.google.com/forum/#!topic/objectify-appengine/uvLIHhHMEM0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.