address #425 for map inserts
This commit is contained in:
parent
c913ffe155
commit
9569b19a34
2 changed files with 26 additions and 11 deletions
|
|
@ -737,14 +737,18 @@
|
|||
;; use the keys from the first map if they match so that
|
||||
;; users can rely on the key ordering if they want to,
|
||||
;; 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)
|
||||
[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')])
|
||||
[[] []]
|
||||
(map (fn [m]
|
||||
(if (map? m)
|
||||
(format-expr-list
|
||||
(map #(get m
|
||||
%
|
||||
|
|
@ -753,7 +757,8 @@
|
|||
(if (contains? *values-default-columns* %)
|
||||
[:default]
|
||||
nil))
|
||||
cols)))
|
||||
cols))
|
||||
[(sql-kw m)]))
|
||||
xs))]
|
||||
(into [(str "("
|
||||
(str/join ", "
|
||||
|
|
|
|||
|
|
@ -751,6 +751,16 @@ ORDER BY id = ? DESC
|
|||
(format {:insert-into [:table [:a :b :c]]
|
||||
:values [[1 [:default] 3] :default]}
|
||||
{: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"
|
||||
(is (= ["INSERT INTO table (a, b, c) VALUES ()"]
|
||||
(format {:insert-into [:table [:a :b :c]]
|
||||
|
|
|
|||
Loading…
Reference in a new issue