views:

183

answers:

1

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 Items")
keyArray = []
for item in items:
  keyArray.append(item.key())
+2  A: 

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.

Nick Johnson
Works like a charm
Fraser Harris