fix #476 by restoring multi-argument :raw

This commit is contained in:
Sean Corfield 2023-03-04 14:21:40 -08:00
parent bfc8ad6821
commit f7cf5718cc
3 changed files with 29 additions and 2 deletions

View file

@ -1,5 +1,8 @@
# Changes # 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 * 2.4.1002 -- 2023-03-03
* Address [#474](https://github.com/seancorfield/honeysql/issues/474) by adding dot-selection special syntax. * 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). * Improve docstrings for PostgreSQL operators via PR [#473](https://github.com/seancorfield/honeysql/pull/473) [@holyjak](https://github.com/holyjak).

View file

@ -1597,8 +1597,12 @@
:else :else
["?" (->param k)])) ["?" (->param k)]))
:raw :raw
(fn [_ [xs]] (fn [_ [& xs]]
(raw-render 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})) :within-group expr-clause-pairs}))
(defn- format-equality-expr [op' op expr nested] (defn- format-equality-expr [op' op expr nested]

View file

@ -1150,3 +1150,23 @@ ORDER BY id = ? DESC
((. (nest w) x)) ((. (nest w) x))
((. (nest (y z)) *)))} ((. (nest (y z)) *)))}
{:dialect :mysql}))))) {: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]])))))