Fixes #286 by supporting WAIT, SKIP LOCKED

NOWAIT was already supported.
This commit is contained in:
Sean Corfield 2021-01-30 11:43:48 -08:00
parent d2968bbfcc
commit 8373c72f45
2 changed files with 11 additions and 3 deletions

View file

@ -301,15 +301,15 @@
[(str (sql-kw k) " " (sql-kw strength)
(when tables
(str
(cond (= :nowait tables)
(str " NOWAIT")
(cond (#{:nowait :skip-locked :wait} tables)
(str " " (sql-kw tables))
(sequential? tables)
(str " OF "
(str/join ", " (map #'format-entity tables)))
:else
(str " OF " (format-entity tables)))
(when nowait
(str " NOWAIT")))))]))
(str " " (sql-kw nowait))))))]))
(defn- format-values [k xs]
(cond (sequential? (first xs))

View file

@ -432,6 +432,14 @@
(format {:select [:*] :from :foo :for [:update :nowait]})))
(is (= ["SELECT * FROM foo FOR UPDATE OF bar NOWAIT"]
(format {:select [:*] :from :foo :for [:update :bar :nowait]})))
(is (= ["SELECT * FROM foo FOR UPDATE WAIT"]
(format {:select [:*] :from :foo :for [:update :wait]})))
(is (= ["SELECT * FROM foo FOR UPDATE OF bar WAIT"]
(format {:select [:*] :from :foo :for [:update :bar :wait]})))
(is (= ["SELECT * FROM foo FOR UPDATE SKIP LOCKED"]
(format {:select [:*] :from :foo :for [:update :skip-locked]})))
(is (= ["SELECT * FROM foo FOR UPDATE OF bar SKIP LOCKED"]
(format {:select [:*] :from :foo :for [:update :bar :skip-locked]})))
(is (= ["SELECT * FROM foo FOR UPDATE OF bar, quux"]
(format {:select [:*] :from :foo :for [:update [:bar :quux]]}))))
(testing "MySQL for/lock"