2010-01-24
Google App Engine notes
text 12:09:00
I’m working on a project that’s using Google App Engine’s datastore for the first time, and I seem to be learning things as I go along, so I thought I’d make a place for jottings.
- To do a join efficiently, add a list of people an object belongs to to the object. Fetch with, eg, Objects.all().filter(‘contact_of =’, contact_of)
- If you have a meaningful identifier (like a Flickr NSID), make that the key:
- object = Object(key_name = id)
- this is a cheap way to guarantee uniqueness
- watch out, though: if you use parent() you can have duplicates
- Fetch a key by name with object = Object.get_by_key_name(id)
- To fetch keys only, use Objects.all(keys_only = True)
- note this is the encoded value
- to get the original ID back, call key.name() on the returned object
- if you used some other identified after key_ in the put, use that instead
- In the GAE console, you need the object type in the GQL query:
- SELECT * FROM Object where __key__ = KEY(‘Object’, ‘key_value’)
- generally I avoid GQL but the admin site only uses it
- Use list comprehensions and sets intersections to find what to operate on
- db.put() can take multiple arguments. Use this to batch datastore writes