From dae09ff601fc775808754def85d611c3bd24e9fb Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 25 Sep 2021 17:06:48 -0700 Subject: [PATCH] fixes #363 by improving inlining capability --- CHANGELOG.md | 1 + build.clj | 7 ++++++- src/honey/sql.cljc | 6 +++--- test/honey/sql_test.cljc | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adeebd4..fcbaad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * 2.0.next in progress * Address #364 by recommending how to handle PostgreSQL operators that contain `@`. + * Fix #363 by aligning more closely the semantics of `:inline` syntax with the `:inline true` option. A side effect of this is that `[:inline [:param :foo]]` will now (correctly) inline the value of the parameter `:foo` whereas it previously produced `PARAMS SOURCE`. In addition, inlining has been extended to vector values, so `[:inline ["a" "b" "c"]]` will now produce `('a', 'b', 'c')` and `[:inline [:lift ["a" "b" "c"]]]` will now produce `['a', 'b', 'c']` which is what people seemed to expect (the behavior was previously unspecified). * Support `AS` aliasing in `DELETE FROM`. * Switch from `readme` to `test-doc-blocks` so all documentation is tested! * Clean up build/update deps. diff --git a/build.clj b/build.clj index efedcd3..2419962 100644 --- a/build.clj +++ b/build.clj @@ -12,7 +12,7 @@ For more information, run: clojure -A:deps -T:build help/doc" - + (:refer-clojure :exclude [test]) (:require [clojure.tools.build.api :as b] [org.corfield.build :as bb])) @@ -43,6 +43,11 @@ [:test-doc-clj]))))) opts) +(defn test "Run basic tests." [opts] + (-> opts + (assoc :aliases [:1.10]) + (bb/run-tests))) + (defn ci "Run the CI pipeline of tests (and build the JAR)." [opts] (-> opts (bb/clean) diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 0fa10dd..98b8a24 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -208,6 +208,7 @@ (nil? x) "NULL" (string? x) (str \' (str/replace x "'" "''") \') (ident? x) (sql-kw x) + (vector? x) (str "[" (str/join ", " (map #'sqlize-value x)) "]") :else (str x))) (defn format-entity @@ -1144,9 +1145,8 @@ :filter expr-clause-pairs :inline (fn [_ [x]] - (if (sequential? x) - [(str/join " " (map #'sqlize-value x))] - [(sqlize-value x)])) + (binding [*inline* true] + (format-expr x))) :interval (fn [_ [n units]] (let [[sql & params] (format-expr n)] diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 8fd56ec..bda1edd 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -447,7 +447,7 @@ (format {:dialect :mysql}))))) (deftest inlined-values-are-stringified-correctly - (is (= ["SELECT 'foo', 'It''s a quote!', BAR, NULL"] + (is (= ["SELECT 'foo', 'It''s a quote!', bar, NULL"] (format {:select [[[:inline "foo"]] [[:inline "It's a quote!"]] [[:inline :bar]]