chickadee » sqdb » update

update db key procprocedure

Updates the value of key by fetching the current value of key, calling (proc val) to get an updated value, and storing that into the database. val will be #f if the key did not exist.

This operation is implemented using an IMMEDIATE transaction, and is atomic as long as you always use update elsewhere (or an IMMEDIATE or EXCLUSIVE transaction) when doing a read-modify-write on this key.

Note that the incr operation could be implemented in a much less efficient way using update:

(update db key (lambda (x) (add1 (or x 0))))
;; Less efficient than:
(add db k 0)
(incr db k)