postmodern-update

Postmodern Examples Table of Contents Insert

Update

In s-sql, updates operate the way you would expect them to, given what we have seen up above.

(query (:update 'countries :set 'text '$1 :where (:= 'id 284)) "now")

Now temporarily assume that we do not have a normalized database and we have a field "region_name" in the countries table in the database and a slot accessor named region-name in the countries class.

We could update a set of the countries rows to get the regional names for a particular set of countries, given a list of countries.id as follows:

(query (:update 'countries :set 'region-name (:select 'name :from 'regions :where (:= 'countries.id 'country-id)) :where (:in 'countries.id (:set 129 139 132 128 135 134 131 137 130 133 136))))
Assume you wanted to update a record with id=5 and you had a plist of the the columns to be updated. 
Assuming you wanted to create something reusable, you could use a query like the following:
(query (sql-compile (append (append `(:update ,table :set) plst) `(:where (:= 'id ,id)))))
Delete
Comments