Again we start with manually updating a Country in our example database.
Query.create("UPDATE country SET name = 'Norway' WHERE id = 1").update();
Again, to avoid SQL injection we'll send in the values as parameters:
Query.create("UPDATE country SET name = :name WHERE id = :id") .param("name", "Norway").param("id", 1).update();
Update an existing domain object:
Query.create("UPDATE country SET name = :name WHERE id = :id") .param(country).update();
We can also supply the country as a named parameter:
Query.create("UPDATE country SET name = :country.name WHERE id = :country.id") .param("country", country).update();
As with INSERT, Tornado Query can automatically write the UPDATE statement for us:
Query.update(countryMapper, country);
Since the countryMapper was created with an id method, it knows how to construct the WHERE clause for the update. This is true even if there are multiple id fields in the Mapper.
NOTE: The Query.update() method will return the number of rows that was altered.