address #425 for map inserts
This commit is contained in:
parent
c913ffe155
commit
9569b19a34
2 changed files with 26 additions and 11 deletions
|
|
@ -737,23 +737,28 @@
|
||||||
;; use the keys from the first map if they match so that
|
;; use the keys from the first map if they match so that
|
||||||
;; users can rely on the key ordering if they want to,
|
;; users can rely on the key ordering if they want to,
|
||||||
;; e.g., see test that uses array-map for the first row
|
;; e.g., see test that uses array-map for the first row
|
||||||
cols-n (into #{} (mapcat keys) xs)
|
cols-n (into #{} (mapcat keys) (filter map? xs))
|
||||||
cols (if (= (set cols-1) cols-n) cols-1 cols-n)
|
cols (if (= (set cols-1) cols-n) cols-1 cols-n)
|
||||||
[sqls params]
|
[sqls params]
|
||||||
(reduce (fn [[sql params] [sqls' params']]
|
(reduce (fn [[sql params] [sqls' params']]
|
||||||
[(conj sql (str "(" (str/join ", " sqls') ")"))
|
[(conj sql
|
||||||
|
(if (sequential? sqls')
|
||||||
|
(str "(" (str/join ", " sqls') ")")
|
||||||
|
sqls'))
|
||||||
(if params' (into params params') params')])
|
(if params' (into params params') params')])
|
||||||
[[] []]
|
[[] []]
|
||||||
(map (fn [m]
|
(map (fn [m]
|
||||||
(format-expr-list
|
(if (map? m)
|
||||||
(map #(get m
|
(format-expr-list
|
||||||
%
|
(map #(get m
|
||||||
;; issue #366: use NULL or DEFAULT
|
%
|
||||||
;; for missing column values:
|
;; issue #366: use NULL or DEFAULT
|
||||||
(if (contains? *values-default-columns* %)
|
;; for missing column values:
|
||||||
[:default]
|
(if (contains? *values-default-columns* %)
|
||||||
nil))
|
[:default]
|
||||||
cols)))
|
nil))
|
||||||
|
cols))
|
||||||
|
[(sql-kw m)]))
|
||||||
xs))]
|
xs))]
|
||||||
(into [(str "("
|
(into [(str "("
|
||||||
(str/join ", "
|
(str/join ", "
|
||||||
|
|
|
||||||
|
|
@ -751,6 +751,16 @@ ORDER BY id = ? DESC
|
||||||
(format {:insert-into [:table [:a :b :c]]
|
(format {:insert-into [:table [:a :b :c]]
|
||||||
:values [[1 [:default] 3] :default]}
|
:values [[1 [:default] 3] :default]}
|
||||||
{:inline true}))))
|
{:inline true}))))
|
||||||
|
(testing "map values with default row, no columns"
|
||||||
|
(is (= ["INSERT INTO table (a, b, c) VALUES (1, 2, 3), DEFAULT, (4, 5, 6)"]
|
||||||
|
(format {:insert-into :table
|
||||||
|
:values [{:a 1 :b 2 :c 3} :default {:a 4 :b 5 :c 6}]}
|
||||||
|
{:inline true}))))
|
||||||
|
(testing "map values with default column, no columns"
|
||||||
|
(is (= ["INSERT INTO table (a, b, c) VALUES (1, DEFAULT, 3), DEFAULT"]
|
||||||
|
(format {:insert-into :table
|
||||||
|
:values [{:a 1 :b [:default] :c 3} :default]}
|
||||||
|
{:inline true}))))
|
||||||
(testing "empty values"
|
(testing "empty values"
|
||||||
(is (= ["INSERT INTO table (a, b, c) VALUES ()"]
|
(is (= ["INSERT INTO table (a, b, c) VALUES ()"]
|
||||||
(format {:insert-into [:table [:a :b :c]]
|
(format {:insert-into [:table [:a :b :c]]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue