Fixes #324 by correcting insert-into

This commit is contained in:
Sean Corfield 2021-05-01 12:56:42 -07:00
parent 20cba15da2
commit 46b3c1773b
3 changed files with 15 additions and 3 deletions

View file

@ -1,6 +1,7 @@
# Changes # Changes
* 2.0.next in progress * 2.0.next in progress
* Fix #324 so that `insert-into` supports merging into another statement in all cases.
* Fix #323 by supporting more than one SQL entity in `:on-conflict`. * Fix #323 by supporting more than one SQL entity in `:on-conflict`.
* Fix #321 by adding `:checking` mode. Currently only detects potential problems with `IN` clauses. * Fix #321 by adding `:checking` mode. Currently only detects potential problems with `IN` clauses.

View file

@ -398,10 +398,12 @@
(-> (select :*) (from :other)))" (-> (select :*) (from :other)))"
{:arglists '([table] [table cols] [table statement] [table cols statement])} {:arglists '([table] [table cols] [table statement] [table cols statement])}
[& args] [& args]
(let [[table cols statement] args] (let [[data & args :as args']
(if (map? (first args)) args (cons {} args))
[table cols statement] args]
(if (and (sequential? cols) (map? statement)) (if (and (sequential? cols) (map? statement))
(generic :insert-into [[table cols] statement]) (generic :insert-into [data [table cols] statement])
(generic :insert-into args)))) (generic :insert-into args'))))
(defn update (defn update
"Accepts either a table name or a table/alias pair. "Accepts either a table name or a table/alias pair.

View file

@ -857,3 +857,12 @@
(where [:or [:= :b 2] [:= :c 3]] [:= :a 1]) (where [:or [:= :b 2] [:= :c 3]] [:= :a 1])
(-> (where :or [:= :b 2] [:= :c 3]) ; explicit or (-> (where :or [:= :b 2] [:= :c 3]) ; explicit or
(where := :a 1)))))) ; then implicit and (where := :a 1)))))) ; then implicit and
(deftest issue-324
(testing "insert-into accepts statement"
(is (= (-> (with [:a])
(insert-into [:quux [:x :y]]
{:select [:id] :from [:table]}))
{:with [[:a]],
:insert-into [[:quux [:x :y]]
{:select [:id], :from [:table]}]}))))