Chapter 7. Data Modeling with Python
Data modeling is the process of translating the data requirements of your application to the features of your data storage technology. While the application deals in players, towns, weapons, potions, and gold, the datastore knows only entities, entity groups, keys, properties, and indexes. The data model describes how the data is stored and how it is manipulated. Entities represent players and game objects; properties describe the status of objects and the relationships between them. When an object changes location, the data is updated in a transaction, so the object cannot be in two places at once. When a player wants to know about the weapons in her inventory, the application performs a query for all weapon objects whose location is the player, possibly requiring an index.
In the last few chapters, we’ve been using the Python class
db.Expando
to create and manipulate entities and their
properties. As we’ve been doing it, this class illustrates the flexible
nature of the datastore. The datastore itself does not impose or enforce a
structure on entities or their properties, giving the application control
over how individual entities represent data objects. This flexibility is
also an essential feature for scalability: changing the structure of
millions of records is a large task, and the proper strategy for doing this
is specific to the task and the application.
But structure is needed. Every player has a number of health points,
and a Player
Get Programming Google App Engine now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.