Programming Google App Engine with Python by Dan Sanderson
Author:Dan Sanderson
Language: eng
Format: epub, mobi, pdf
Publisher: O'Reilly Media, Inc.
Published: 2015-06-16T16:00:00+00:00
@ndb.transactional(xg=True): def update_win_tallies(winning_player, losing_player): # ...
Chapter 9. Data Modeling with ndb
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, while 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.
In the last few chapters, we’ve been using the Python class ndb.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 entity without a health property, or with a health property whose value is not an integer, is likely to confuse the battle system. The data ought to conform to a structure, or schema, to meet the expectations of the code. Because the datastore does not enforce this schema itself—the datastore is schemaless—it is up to the application to ensure that entities are created and updated properly.
App Engine includes a data modeling library for defining and enforcing data schemas in Python called ndb.1 This library resides in the google.appengine.ext.ndb package. It includes several related classes for representing data objects, including ndb.Model, ndb.Expando, and ndb.PolyModel. To give structure to entities of a given kind, you create a subclass of one of these classes. The definition of the class specifies the properties for those objects, their allowed value types, and other requirements.
In this chapter, we’ll introduce the ndb data modeling library and discuss how to use it to enforce a schema for the otherwise schemaless datastore. We’ll also discuss how the library works and how to extend it. Finally, we’ll look at the ndb library’s powerful performance-related features for managing data caches.
Download
Programming Google App Engine with Python by Dan Sanderson.mobi
Programming Google App Engine with Python by Dan Sanderson.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
What's Done in Darkness by Kayla Perrin(26518)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19001)
The Fifty Shades Trilogy & Grey by E L James(18953)
Shot Through the Heart by Mercy Celeste(18877)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(16976)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(16869)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(16796)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16691)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16316)
The Subtle Art of Not Giving a F*ck by Mark Manson(14251)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14068)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13414)
Scorched Earth by Nick Kyme(12708)
Drei Generationen auf dem Jakobsweg by Stein Pia(10919)
Suna by Ziefle Pia(10843)
Scythe by Neal Shusterman(10265)
International Relations from the Global South; Worlds of Difference; First Edition by Arlene B. Tickner & Karen Smith(9473)
Successful Proposal Strategies for Small Businesses: Using Knowledge Management ot Win Govenment, Private Sector, and International Contracts 3rd Edition by Robert Frey(9313)
This is Going to Hurt by Adam Kay(9090)
