From 8373c72f45170ef7f3d4cc4fe59399fc2cdf08be Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 30 Jan 2021 11:43:48 -0800 Subject: [PATCH] Fixes #286 by supporting WAIT, SKIP LOCKED NOWAIT was already supported. --- src/honey/sql.cljc | 6 +++--- test/honey/sql_test.cljc | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 0971799..07657a4 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -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)) diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index de5706d..9af6179 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -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"