From da88383cc0ae29fe7236efd0510950c74bacd562 Mon Sep 17 00:00:00 2001 From: Donald Ball Date: Sun, 19 Apr 2015 21:57:44 -0400 Subject: [PATCH] Document locking selects --- CHANGES.md | 1 + README.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 102c111..5d56d54 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## 0.5.3 In development +* Support locking selects (@dball) * Add sql array type and reader literal (@loganmhb) ## 0.5.2 diff --git a/README.md b/README.md index a184be2..cd2cb6a 100644 --- a/README.md +++ b/README.md @@ -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