开发者

gqlQuery returns object, want list of keys

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜