diff --git a/CHANGELOG.md b/CHANGELOG.md index d896711..d73c680 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 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 #321 by adding `:checking` mode. Currently only detects potential problems with `IN` clauses. diff --git a/src/honey/sql/helpers.cljc b/src/honey/sql/helpers.cljc index 95dde1a..8c9f40d 100644 --- a/src/honey/sql/helpers.cljc +++ b/src/honey/sql/helpers.cljc @@ -398,10 +398,12 @@ (-> (select :*) (from :other)))" {:arglists '([table] [table cols] [table statement] [table cols statement])} [& 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)) - (generic :insert-into [[table cols] statement]) - (generic :insert-into args)))) + (generic :insert-into [data [table cols] statement]) + (generic :insert-into args')))) (defn update "Accepts either a table name or a table/alias pair. diff --git a/test/honey/sql/helpers_test.cljc b/test/honey/sql/helpers_test.cljc index 355bf71..33ea68c 100644 --- a/test/honey/sql/helpers_test.cljc +++ b/test/honey/sql/helpers_test.cljc @@ -857,3 +857,12 @@ (where [:or [:= :b 2] [:= :c 3]] [:= :a 1]) (-> (where :or [:= :b 2] [:= :c 3]) ; explicit or (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]}]}))))