I've migrated a 1st Gen GAE Python 2 app to 2nd Gen GAE Python 3. It was not easy but everything seems to be working.
I'd now like to migrate from google-cloud-ndb to google-cloud-datastore. With google-cloud-datastore, is it ok to subclass Entity (which is a dict subclass) in a similar way to subclassing ndb.Model?
For example google-cloud-ndb code looks like this:
from google.cloud import ndb
class Foo(ndb.Model):
x = ndb.StringProperty(default='42')
def do_something(self):
pass
Is this the right way to migrate the above to google-cloud-datastore?:
from google.cloud.datastore.entity import Entity
class Foo(Entity):
def __init__(self):
super().__init__()
self['x'] = '42'
def do_something(self):
pass
I haven't seen any example code like this so I'd like to confirm that this is a good practice, especially with overriding __init__.
Even better, is there a way to subclass Entity so that I could access the data as object attributes (foo.x) instead of as a dictionary (foo['x'])? That would make migration much easier.