Question

I have a beginner question.

I was reading the GAE reference and I only saw "SELECT" operation. I would need the counterparts of SQL's UPDATE and DELETE but all I could figure is this:

DELETE: .filter from the table to get to an item then call .remove() on it.
UPDATE: .filter from the table to get to an item then modify it and insert it back with .put(), but call .remove() on the original element.

Is this the proper and efficient way of doing these operations?

Was it helpful?

Solution

Update is essentially same as put when the element already exist. GAE will rewrite the entity when you do .put()

Example
Update
mymodel = MyModel.get_by_key_name('myKey')
mymodel.x = 123
mymodel.put()

OTHER TIPS

No

GQL is not SQL.

You need to manipulate the entities in the datastore via models and keys.

Firstly you should consider abandoning all your preconceived ideas on how the datastore should work based on your SQL knowlege, once mentally prepared work through the getting started guide https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingdatastore

Then progress to the docs on the Datastore. https://developers.google.com/appengine/docs/python/datastore/

If you have no preexisting appengine code base then use ndb rather than db.

If you need true SQL capabilities then look at Google Cloud SQL rather than the appengine datastore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top