Skip to content

Instantly share code, notes, and snippets.

@proppy
Created January 30, 2014 20:41
Show Gist options
  • Save proppy/8718248 to your computer and use it in GitHub Desktop.
Save proppy/8718248 to your computer and use it in GitHub Desktop.
>>> 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)]
@jgeewax
Copy link

jgeewax commented Jan 30, 2014

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 calling query.limit(10) isn't a 'setter' but really a factor for a new Query with all the properties of query 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).

@jgeewax
Copy link

jgeewax commented Jan 30, 2014

(Adding a back-reference: googleapis/google-cloud-python#3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment