fixes #363 by improving inlining capability

This commit is contained in:
Sean Corfield 2021-09-25 17:06:48 -07:00
parent e44a30a7fd
commit dae09ff601
4 changed files with 11 additions and 5 deletions

View file

@ -2,6 +2,7 @@
* 2.0.next in progress * 2.0.next in progress
* Address #364 by recommending how to handle PostgreSQL operators that contain `@`. * 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`. * Support `AS` aliasing in `DELETE FROM`.
* Switch from `readme` to `test-doc-blocks` so all documentation is tested! * Switch from `readme` to `test-doc-blocks` so all documentation is tested!
* Clean up build/update deps. * Clean up build/update deps.

View file

@ -12,7 +12,7 @@
For more information, run: For more information, run:
clojure -A:deps -T:build help/doc" clojure -A:deps -T:build help/doc"
(:refer-clojure :exclude [test])
(:require [clojure.tools.build.api :as b] (:require [clojure.tools.build.api :as b]
[org.corfield.build :as bb])) [org.corfield.build :as bb]))
@ -43,6 +43,11 @@
[:test-doc-clj]))))) [:test-doc-clj])))))
opts) 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] (defn ci "Run the CI pipeline of tests (and build the JAR)." [opts]
(-> opts (-> opts
(bb/clean) (bb/clean)

View file

@ -208,6 +208,7 @@
(nil? x) "NULL" (nil? x) "NULL"
(string? x) (str \' (str/replace x "'" "''") \') (string? x) (str \' (str/replace x "'" "''") \')
(ident? x) (sql-kw x) (ident? x) (sql-kw x)
(vector? x) (str "[" (str/join ", " (map #'sqlize-value x)) "]")
:else (str x))) :else (str x)))
(defn format-entity (defn format-entity
@ -1144,9 +1145,8 @@
:filter expr-clause-pairs :filter expr-clause-pairs
:inline :inline
(fn [_ [x]] (fn [_ [x]]
(if (sequential? x) (binding [*inline* true]
[(str/join " " (map #'sqlize-value x))] (format-expr x)))
[(sqlize-value x)]))
:interval :interval
(fn [_ [n units]] (fn [_ [n units]]
(let [[sql & params] (format-expr n)] (let [[sql & params] (format-expr n)]

View file

@ -447,7 +447,7 @@
(format {:dialect :mysql}))))) (format {:dialect :mysql})))))
(deftest inlined-values-are-stringified-correctly (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"]] (format {:select [[[:inline "foo"]]
[[:inline "It's a quote!"]] [[:inline "It's a quote!"]]
[[:inline :bar]] [[:inline :bar]]