addresses #366 -- needs documentation!

This commit is contained in:
Sean Corfield 2021-10-03 22:32:05 -07:00
parent 6aee04e25c
commit 3cacec9c32
2 changed files with 13 additions and 2 deletions

View file

@ -2,6 +2,7 @@
* 2.0.next in progress
* Fix #367 by supporting parameters in subexpressions around `IS NULL` / `IS NOT NULL` tests.
* Address #366 by introducing `:values-default-columns` option to control whether missing columns are treated as `NULL` or `DEFAULT` in `:values` clauses with sequences of hash maps. TODO: NEEDS DOCUMENTATION UPDATES INCLUDING EXAMPLE USAGE!
* Fix #365 -- a regression from 1.x -- where subclauses for `UNION`, `EXCEPT`, etc were incorrectly parenthesized.
* Update `build-clj` to v0.5.0.

View file

@ -108,6 +108,7 @@
(def ^:private ^:dynamic *quoted-snake* nil)
(def ^:private ^:dynamic *inline* nil)
(def ^:private ^:dynamic *params* nil)
(def ^:private ^:dynamic *values-default-columns* nil)
;; there is no way, currently, to enable suspicious characters
;; in entities; if someone complains about this check, an option
;; can be added to format to turn this on:
@ -621,7 +622,15 @@
(if params' (into params params') params')])
[[] []]
(map (fn [m]
(format-expr-list (map #(get m %) cols)))
(format-expr-list
(map #(get m
%
;; issue #366: use NULL or DEFAULT
;; for missing column values:
(if (contains? *values-default-columns* %)
[:default]
nil))
cols)))
xs))]
(into [(str "("
(str/join ", "
@ -1330,7 +1339,8 @@
@default-quoted)
*quoted-snake* (when (contains? opts :quoted-snake)
(:quoted-snake opts))
*params* (:params opts)]
*params* (:params opts)
*values-default-columns* (:values-default-columns opts)]
(mapv #(unwrap % opts) (format-dsl data opts)))))
([data k v & {:as opts}] (format data (assoc opts k v))))