Loading and saving data
Now that we know how to connect to a Cloud SQL instance from our App Engine application, it's time to learn how to write and read data from the database. We already created a table called ops
, and we will use it to store information about user operations. We will log the following events:
- A user has created a note
- A user has added a file
- A user has performed a shrink operation
We have to assign a text code to each of the operation types we want to log. To do so, we can use a simple Python class that works as an enumeration. In the utils.py
module, we add the following code:
class OpTypes(object): NOTE_CREATED = 'NCREATED' FILE_ADDED = 'FADDED' SHRINK_PERFORMED = 'SHRINKED'
We will see how to use it in a moment. We now provide ...
Get Python for 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.