parent
150fcda6d3
commit
084c1ec5e5
3 changed files with 33 additions and 7 deletions
|
|
@ -1,6 +1,7 @@
|
|||
# Changes
|
||||
|
||||
* 2.6.next in progress
|
||||
* Fix [#543](https://github.com/seancorfield/honeysql/issues/543) by supporting both symbols and keywords in named parameters.
|
||||
* Getting Started updated based on feedback from Los Angeles Clojure meetup walkthrough [#539](https://github.com/seancorfield/honeysql/issues/539).
|
||||
* Update Clojure version to 1.12.0.
|
||||
|
||||
|
|
|
|||
|
|
@ -1920,12 +1920,13 @@
|
|||
(into [(str/join ", " sqls)] params)))
|
||||
:param
|
||||
(fn [_ [k]]
|
||||
(cond *inline*
|
||||
[(sqlize-value (param-value k))]
|
||||
*numbered*
|
||||
(->numbered-param k)
|
||||
:else
|
||||
["?" (->param k)]))
|
||||
(let [k (sym->kw k)]
|
||||
(cond *inline*
|
||||
[(sqlize-value (param-value k))]
|
||||
*numbered*
|
||||
(->numbered-param k)
|
||||
:else
|
||||
["?" (->param k)])))
|
||||
:raw
|
||||
(fn [_ [& xs]]
|
||||
;; #476 : preserve existing single-argument behavior...
|
||||
|
|
@ -2124,7 +2125,10 @@
|
|||
*quoted-snake* (if (contains? opts :quoted-snake)
|
||||
(:quoted-snake opts)
|
||||
@default-quoted-snake)
|
||||
*params* (:params opts)
|
||||
*params* (reduce-kv (fn [m k v]
|
||||
(assoc m (sym->kw k) v))
|
||||
{}
|
||||
(:params opts))
|
||||
*values-default-columns* (:values-default-columns opts)]
|
||||
(if cache
|
||||
(->> (through-opts opts cache data (fn [_] (formatter data (dissoc opts :cache))))
|
||||
|
|
|
|||
|
|
@ -1351,6 +1351,27 @@ ORDER BY id = ? DESC
|
|||
:from [[{:values [[1 2 3] [4 5 6]]}
|
||||
[:t [:composite :a :b :c]]]]}))))
|
||||
|
||||
(deftest issue-543-param
|
||||
(testing "quoted param with symbol param"
|
||||
(is (= ["SELECT a FROM table WHERE x = ?" 42]
|
||||
(sut/format '{select a from table where (= x (param y))}
|
||||
{:params {'y 42}})))
|
||||
(is (= ["SELECT a FROM table WHERE x = ?" 42]
|
||||
(sut/format '{select a from table where (= x ?y)}
|
||||
{:params {'y 42}}))))
|
||||
(testing "quoted param with keyword param"
|
||||
(is (= ["SELECT a FROM table WHERE x = ?" 42]
|
||||
(sut/format '{select a from table where (= x (param y))}
|
||||
{:params {:y 42}})))
|
||||
(is (= ["SELECT a FROM table WHERE x = ?" 42]
|
||||
(sut/format '{select a from table where (= x :?y)}
|
||||
{:params {:y 42}}))))
|
||||
(testing "all combinations"
|
||||
(doseq [p1 [:y 'y] p2 [:y 'y]]
|
||||
(is (= ["SELECT a FROM table WHERE x = ?" 42]
|
||||
(sut/format {:select :a :from :table :where [:= :x [:param p1]]}
|
||||
{:params {p2 42}}))))))
|
||||
|
||||
(comment
|
||||
;; partial (incorrect!) workaround for #407:
|
||||
(sut/format {:select :f.* :from [[:foo [:f :for :system-time]]] :where [:= :f.id 1]})
|
||||
|
|
|
|||
Loading…
Reference in a new issue