diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a3bf67..9a46679 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changes +* 2.4.next in progress + * Fix [#476](https://github.com/seancorfield/honeysql/issues/476) by adding support for multiple arguments to `:raw`, essentially restoring 1.x functionality (while still allowing for embedded vectors as expressions, introduced in 2.x). + * 2.4.1002 -- 2023-03-03 * Address [#474](https://github.com/seancorfield/honeysql/issues/474) by adding dot-selection special syntax. * Improve docstrings for PostgreSQL operators via PR [#473](https://github.com/seancorfield/honeysql/pull/473) [@holyjak](https://github.com/holyjak). diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 227df62..771b05e 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -1597,8 +1597,12 @@ :else ["?" (->param k)])) :raw - (fn [_ [xs]] - (raw-render xs)) + (fn [_ [& xs]] + ;; #476 : preserve existing single-argument behavior... + (if (= 1 (count xs)) + (raw-render (first xs)) + ;; ...but allow for multiple arguments now: + (raw-render xs))) :within-group expr-clause-pairs})) (defn- format-equality-expr [op' op expr nested] diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index be4d84a..5e7c76a 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -1150,3 +1150,23 @@ ORDER BY id = ? DESC ((. (nest w) x)) ((. (nest (y z)) *)))} {:dialect :mysql}))))) + +(deftest issue-476-raw + (testing "single argument :raw" + (is (= ["@foo := 42"] + (sut/format [:raw "@foo := 42"]))) + (is (= ["@foo := 42"] + (sut/format [:raw ["@foo := 42"]]))) + (is (= ["@foo := 42"] + (sut/format [:raw ["@foo := " 42]]))) + (is (= ["@foo := (?)" 42] + (sut/format [:raw ["@foo := " [42]]]))) + (is (= ["@foo := MYFUNC(?)" 42] + (sut/format [:raw ["@foo := " [:myfunc 42]]])))) + (testing "multi-argument :raw" + (is (= ["@foo := 42"] + (sut/format [:raw "@foo := " 42]))) + (is (= ["@foo := (?)" 42] + (sut/format [:raw "@foo := " [42]]))) + (is (= ["@foo := MYFUNC(?)" 42] + (sut/format [:raw "@foo := " [:myfunc 42]])))))