Fix using maps with different key orders in :values
This commit is contained in:
parent
7b61250b2d
commit
bdfee0883e
2 changed files with 12 additions and 5 deletions
|
|
@ -541,10 +541,11 @@
|
|||
(if (sequential? (first values))
|
||||
(str "VALUES " (comma-join (for [x values]
|
||||
(str "(" (comma-join (map to-sql x)) ")"))))
|
||||
(let [cols (keys (first values))]
|
||||
(str
|
||||
"(" (comma-join (map to-sql (keys (first values)))) ") VALUES "
|
||||
"(" (comma-join (map to-sql cols)) ") VALUES "
|
||||
(comma-join (for [x values]
|
||||
(str "(" (comma-join (map to-sql (vals x))) ")"))))))
|
||||
(str "(" (comma-join (map #(to-sql (get x %)) cols)) ")")))))))
|
||||
|
||||
(defmethod format-clause :query-values [[_ query-values] _]
|
||||
(to-sql query-values))
|
||||
|
|
|
|||
|
|
@ -84,6 +84,12 @@
|
|||
(insert-into :foo)
|
||||
(columns :bar)
|
||||
(values [[(honeysql.format/value {:baz "my-val"})]])
|
||||
sql/format)))
|
||||
(is (= ["INSERT INTO foo (a, b, c) VALUES (?, ?, ?), (?, ?, ?)"
|
||||
"a" "b" "c" "a" "b" "c"]
|
||||
(-> (insert-into :foo)
|
||||
(values [(array-map :a "a" :b "b" :c "c")
|
||||
(hash-map :a "a" :b "b" :c "c")])
|
||||
sql/format))))
|
||||
|
||||
(deftest test-operators
|
||||
|
|
|
|||
Loading…
Reference in a new issue