basic testing for numbered params
This commit is contained in:
parent
359d9de668
commit
4ea630ed90
2 changed files with 34 additions and 2 deletions
|
|
@ -326,13 +326,13 @@
|
|||
(let [n (count (swap! *numbered* conj v))]
|
||||
[(str "$" n) (with-meta (constantly (dec n))
|
||||
{::wrapper
|
||||
(fn [fk _] (get *numbered* (fk)))})]))
|
||||
(fn [fk _] (get @*numbered* (fk)))})]))
|
||||
|
||||
(defn ->numbered-param [k]
|
||||
(let [n (count (swap! *numbered* conj k))]
|
||||
[(str "$" n) (with-meta (constantly k)
|
||||
{::wrapper
|
||||
(fn [fk _] (param-value (get *numbered* (fk))))})]))
|
||||
(fn [fk _] (param-value (get @*numbered* (fk))))})]))
|
||||
|
||||
(def ^:private ^:dynamic *formatted-column* (atom false))
|
||||
|
||||
|
|
|
|||
|
|
@ -94,6 +94,38 @@
|
|||
(is (= ["SELECT * FROM \"table\" WHERE \"id\" IN (?, ?, ?, ?)" 1 2 3 4]
|
||||
(sut/format {:select [:*] :from [:table] :where [:in :id [1 2 3 4]]} {:quoted true}))))
|
||||
|
||||
(deftest general-numbered-tests
|
||||
(is (= ["SELECT * FROM \"table\" WHERE \"id\" = $1" 1]
|
||||
(sut/format {:select [:*] :from [:table] :where [:= :id 1]}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT * FROM \"table\" WHERE \"id\" = $1" 1]
|
||||
(sut/format {:select [:*] :from [:table] :where (sut/map= {:id 1})}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT \"t\".* FROM \"table\" AS \"t\" WHERE \"id\" = $1" 1]
|
||||
(sut/format {:select [:t.*] :from [[:table :t]] :where [:= :id 1]}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT * FROM \"table\" GROUP BY \"foo\", \"bar\""]
|
||||
(sut/format {:select [:*] :from [:table] :group-by [:foo :bar]}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT * FROM \"table\" GROUP BY DATE(\"bar\")"]
|
||||
(sut/format {:select [:*] :from [:table] :group-by [[:date :bar]]}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT * FROM \"table\" ORDER BY \"foo\" DESC, \"bar\" ASC"]
|
||||
(sut/format {:select [:*] :from [:table] :order-by [[:foo :desc] :bar]}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT * FROM \"table\" ORDER BY DATE(\"expiry\") DESC, \"bar\" ASC"]
|
||||
(sut/format {:select [:*] :from [:table] :order-by [[[:date :expiry] :desc] :bar]}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT * FROM \"table\" WHERE DATE_ADD(\"expiry\", INTERVAL $1 DAYS) < NOW()" 30]
|
||||
(sut/format {:select [:*] :from [:table] :where [:< [:date_add :expiry [:interval 30 :days]] [:now]]}
|
||||
{:quoted true :numbered true})))
|
||||
(is (= ["SELECT * FROM `table` WHERE `id` = $1" 1]
|
||||
(sut/format {:select [:*] :from [:table] :where [:= :id 1]}
|
||||
{:dialect :mysql :numbered true})))
|
||||
(is (= ["SELECT * FROM \"table\" WHERE \"id\" IN ($1, $2, $3, $4)" 1 2 3 4]
|
||||
(sut/format {:select [:*] :from [:table] :where [:in :id [1 2 3 4]]}
|
||||
{:quoted true :numbered true}))))
|
||||
|
||||
;; issue-based tests
|
||||
|
||||
(deftest subquery-alias-263
|
||||
|
|
|
|||
Loading…
Reference in a new issue