Closed
Description
These exist to an extent but aren't universal and certainly not well documented.
There are two options:
- Create an object to manage namespaces
from gcloud import datastore
dataset = datastore.get_dataset(...)
namespace = dataset.namespace('my-namespace')
person = namespace.entity('Person')
person['name'] = 'JJ'
person.save()
query = namespace.query('Person')
print query.fetch()
- Allow users to pass a namespace argument to various constructors (and set namespaces with a method, akin to setting a kind or id on a Key).
from gcloud import datastore
dataset = datastore.get_dataset(...)
person = dataset.entity('Person')
person.namespace('my-namespace')
person['name'] = 'JJ'
person.save()
query = dataset.query('Person').namespace('my-namespace')
print query.fetch()
or
person = namespace.entity('Person')
person['name'] = 'JJ'
person.save(namespace='my-namespace')
I currently prefer option 2, where a namespace isn't a separate level in the hierarchy, but simply a flag passed around on queries or entities.