diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cff242..17fb249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 2.6.next in progress + * Address [#568](https://github.com/seancorfield/honeysql/issues/568) by adding `honey.sql/semicolon` to merge multiple SQL+params vectors into one (with semicolons separating the SQL statements). * Address [#567](https://github.com/seancorfield/honeysql/issues/567) by adding support for `ASSERT` clause. * Address [#566](https://github.com/seancorfield/honeysql/issues/566) by adding `IS [NOT] DISTINCT FROM` operators. * Add examples of `:alias` with `:group-by` (syntax is slightly different to existing examples for `:order-by`). diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 174d379..4bcf9f8 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -2517,6 +2517,22 @@ (first clauses) (into [:and] clauses)))) +(defn semicolon + "Given either a vector of formatted SQL+params vectors, or two or more + SQL+params vectors as arguments, merge them into a single SQL+params + vector with the SQL strings separated by semicolons." + ([sql+params-vector] + (reduce into + [(str/join "; " (map first sql+params-vector))] + (map rest sql+params-vector))) + ([sql+params & more] + (semicolon (cons sql+params more)))) + +(comment + (semicolon [ ["foo" 1 2 3] ["bar" 4 5 6] ]) + (semicolon ["foo" 1 2 3] ["bar" 4 5 6] ["baz" 7 8 9] ) + ) + ;; aids to migration from HoneySQL 1.x -- these are deliberately undocumented ;; so as not to encourage their use for folks starting fresh with 2.x!