Document locking selects

This commit is contained in:
Donald Ball 2015-04-19 21:57:44 -04:00
parent 72784452b9
commit da88383cc0
2 changed files with 16 additions and 0 deletions

View file

@ -1,5 +1,6 @@
## 0.5.3 In development
* Support locking selects (@dball)
* Add sql array type and reader literal (@loganmhb)
## 0.5.2

View file

@ -215,6 +215,21 @@ To quote identifiers, pass the `:quoting` keyword option to `format`. Valid opti
=> ["SELECT `foo`.`a` FROM `foo` WHERE `foo`.`a` = ?" "baz"]
```
To issue a locking select, add a :lock to the query or use the lock helper. The lock value must be a map with a :mode value. The built-in
modes are the standard :update (FOR UPDATE) or the vendor-specific :mysql-share (LOCK IN SHARE MODE) or :postresql-share (FOR SHARE). The
lock map may also provide a :wait value, which if false will append the NOWAIT parameter, supported by PostgreSQL.
```clj
(-> (select :foo.a)
(from :foo)
(where [:= foo.a "baz"])
(lock {:mode :update})
(sql/format))
=> ["SELECT foo.a FROM foo WHERE foo.a = ? FOR UPDATE" "baz"]
```
To support novel lock modes, implement the `format-lock-clause` multimethod.
Here's a big, complicated query. Note that Honey SQL makes no attempt to verify that your queries make any sense. It merely renders surface syntax.
```clj