开发者

gqlQuery returns object, want list of keys

开发者 https://www.devze.com 2022-12-11 04:18 出处:网络
Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys?For example:

Is there a way to convert the GqlQuery object to an array of keys, or is there a way to force the query to return an array of keys? For example:

items = db.GqlQuery("SELECT __key__ FROM Items")

returns an object containing the keys:

<google.appengine.ext.db.GqlQuery object at 0x0415E210>

I need to compare it to an array of keys that look like:

[datastore_types.Key.from_path(u'Item', 100L, _app_id_namespace=u'items'),
 ..., datastore_types.Key.from_path(u'Item', 105L, _app_id_namespace=u'fitems')]

Note: I can get around the problem by querying for the stored objects, and then calling .key(), but this seems wasteful.

items = db.GqlQuery("SELECT * FROM Ite开发者_开发技巧ms")
keyArray = []
for item in items:
  keyArray.append(item.key())


Certainly - you can fetch the results by calling .fetch(count) on the GqlQuery object. This is the recommended way, in fact - iterating fetches results in batches, and so is less efficient.

0

精彩评论

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

关注公众号