Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are Google App Engine model classes stored?

I'm in doubt how the objects are stored. Say I have a class defined like:

class SomeEntity(db.Model):
    some_number = db.IntegerProperty(required=True)

    def calculate_something(self):
        return self.some_number * 2

My guess is that the only thing stored in the data store is the name/value/type of some_number together with the fully qualified name of the class (SomeEntity). However I have not stumbled upon any information that confirms this.

1) Can anyone confirm this?

I would like to confirm that I can change (and add/remove) methods without somehow affecting the data is stored.

2) Furthermore, what happens to existing objects if I add a new property to the class (and what if that property has required=true)?

like image 664
Klaus Byskov Pedersen Avatar asked Nov 17 '10 19:11

Klaus Byskov Pedersen


People also ask

What are the different ways of storing application data in Google App Engine?

To store data and files on App Engine, you can use Google Cloud services or any other storage service that is supported by your language and is accessible from your App Engine instance. Third-party databases can be hosted on another cloud provider, hosted on premises, or managed by a third-party vendor.

What is the fundamental storage service of Google App Engine?

Google App Engine (GAE) is a platform-as-a-service product that provides web app developers and enterprises with access to Google's scalable hosting and tier 1 internet service. GAE requires that applications be written in Java or Python, store data in Google Bigtable and use the Google query language.

How does Google App Engine Works?

App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. You can choose from several popular languages, libraries, and frameworks to develop your apps, and then let App Engine take care of provisioning servers and scaling your app instances based on demand.

Under which category does Google App Engine Gae fall?

Google App Engine (GAE) is a service for developing and hosting Web applications in Google's data centers, belonging to the platform as a service (PaaS) category of cloud computing.


2 Answers

Entities are stored in the datastore in a protobuf representation (including its key - which includes your App ID and the entity's Kind). The Life of a Datastore Write article talks more about the representation of entities and how they are written to the datastore. Check out the rest of the articles in this series for more detailed information.

1) Methods have no bearing on the data stored with your entity, so you can add/remove/change these without affecting the representation of your data.

2) The datastore is schemaless (unlike the typical SQL database). Changing your Model has no impact on the data in the datastore at all. When you retrieve an existing entity, if it is missing a required field then an error will be raised. Alternatively, if you don't make it required and provide a default, then the default will be used for the missing field.

If you need to migrate an old model to a new one, you might want to consider using the appengine-mapreduce library to iterate over all of your entities and migrate each one individually. Read more about schema migration here.

like image 107
David Underhill Avatar answered Oct 20 '22 00:10

David Underhill


They are stored as protocol buffers. You can read about some of the details in the "How Entities and Indexes are Stored" article.

You can see what is actually stored with:

db.model_to_protobuf(your_entity)

It is safe to add / remove methods, just be careful about overwriting built-in methods.

Include a default value if you add a property that is required. Existing entities will not be updated until you re-put the entity.

like image 43
Robert Kluin Avatar answered Oct 20 '22 00:10

Robert Kluin