pts
pts

Reputation: 87221

partial ancestor fetches before deletion from the AppEngine datastore

I'd like to delete a bunch of objects from the AppEngine datastore within a transaction:

def F():
  items_to_delete = []
  for item in db.Query().ancestor(...):
    if item.aaa ... item.bbb:
      items_to_delete.append(item)
  db.delete(items_to_delete)
db.run_in_transaction(F)

Is it possible to fetch only a few fields of the items (aaa and bbb)? Will such a fetch have a positive effect on performance?

Upvotes: 1

Views: 123

Answers (2)

Alvin K.
Alvin K.

Reputation: 4379

Check out NDB tutorial, written by Guido himself (bow to ground and say "I'm not worthy" x 3 :). He uses AND OR in query and fetching a few fields with offset (that answers your question). Still experimental though, so use with caution until it is out of preview.

Upvotes: 0

David Hu
David Hu

Reputation: 3136

It's not possible to fetch only a few fields; i.e. you'll always be fetching the entire entity with all its fields (or just the entity keys). From the App Engine GQL reference docs:

The GQL syntax can be summarized as follows:   
    SELECT [* | __key__]
        [FROM <kind>]]
        [WHERE <condition> [AND <condition> ...]]
        [ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
        [LIMIT [<offset>,]<count>]
        [OFFSET <offset>]

and

A GQL query returns zero or more entities or Keys of the requested kind. Every GQL query always begins with either SELECT * or SELECT __key__. (A GQL query cannot perform a SQL-like "join" query.) Tip: SELECT __key__ queries are faster and cost less CPU than SELECT * queries.

Upvotes: 3

Related Questions