Database Reference
In-Depth Information
an attempt counter. You can also use AppEngine task queues instead of
a separate cron job, but the individual steps are basically the same. Refer
to the sample application for the complete implementation of this periodic
loading scheme.
Mixing Types
The start of this section discussed that going from NoSQL storage to a
strictly typed storage introduces complications. However, in the previous
example everything seems to have gone smoothly. This is because we did not
actually use any of the NoSQL flexibility. Now take a look at what happens
when you do exercise some of the features. When we defined the model
for Device entities, we chose to use an IntegerProperty to represent the
number of gigabytes of storage present in a device.
True Story
This example may seem a bit contrived, but one of the authors actually
ran into this scenario. Developing the application in 2013, it was easy to
assume that every phone model would have a couple of GB of storage.
When an actual catalog of models was consulted, there were a number
of models with less than 1 GB of storage released as recently as 2012.
Say you need to update your model to support fractional gigabytes. You
could update your model to use a FloatProperty for the field instead.
class Device(ndb.Model):
storage_gb = ndb.FloatProperty(indexed=False)
Observe that we have updated the type of the field but retained the same
name. When we update the application and add a new device, everything
works just fine. Datastore does not mind that we have some entities with an
integer for storage_gb and others with a floating-point value.
Search WWH ::




Custom Search