Created
January 30, 2014 20:41
-
-
Save proppy/8718248 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from gcloud import datastore | |
>>> dataset = datastore.dataset('foo') | |
>>> entity = dataset.entity('Foo', 1) # complete key | |
>>> entity.key | |
('Foo', 1L) | |
>>> entity.save() # or dataset.upsert(entity) | |
>>> entity = dataset.entity('Foo') # incomplete key | |
>>> entity.key | |
('Foo',) | |
>>> entity.save() # or dataset.upsert(entity) | |
>>> entity.key | |
('Foo', 1001L) # auto allocated ids | |
>>> entity = dataset.entity('Parent', 'name', 'Foo', 2) | |
>>> entity.key | |
('Parent', 'name', 'Foo', 2) | |
>>> entity.save() # or dataset.upsert(entity) | |
>>> dataset.lookup([('Parent', 'name', 'Foo', 2), ('Foo', 1)]) | |
[Entity('Parent', 'name', 'Foo', 2), ('Foo', 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Subtle, but looks like entity.key is a property (or just an attribute), which it isn't currently. I'm fine with changing it to be, because
Entity
is mutable. This wouldn't work for an immutable object, where callingquery.limit(10)
isn't a 'setter' but really a factor for a newQuery
with all the properties ofquery
and a limit of 10.I like the syntax of
dataset.lookup()
. I'd like it to return Entity objects (looks like the second is just a Key tuple).