Apply seq to sets when converting to sql
This allows them to be used as values, e.g. for in clauses, as demonstrated in the test.
This commit is contained in:
parent
53b37c1c10
commit
2820662f59
3 changed files with 14 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
## 0.5.3 In development
|
## 0.5.3 In development
|
||||||
|
|
||||||
|
* Apply seq to sets when converting to sql (@dball)
|
||||||
* Support locking selects (@dball)
|
* Support locking selects (@dball)
|
||||||
* Add sql array type and reader literal (@loganmhb)
|
* Add sql array type and reader literal (@loganmhb)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -320,6 +320,9 @@
|
||||||
(if *subquery?*
|
(if *subquery?*
|
||||||
(paren-wrap sql-str)
|
(paren-wrap sql-str)
|
||||||
sql-str)))
|
sql-str)))
|
||||||
|
clojure.lang.IPersistentSet
|
||||||
|
(-to-sql [x]
|
||||||
|
(-to-sql (seq x)))
|
||||||
nil
|
nil
|
||||||
(-to-sql [x] "NULL")
|
(-to-sql [x] "NULL")
|
||||||
SqlParam
|
SqlParam
|
||||||
|
|
|
||||||
|
|
@ -80,3 +80,13 @@
|
||||||
(columns :bar)
|
(columns :bar)
|
||||||
(values [[(honeysql.format/value {:baz "my-val"})]])
|
(values [[(honeysql.format/value {:baz "my-val"})]])
|
||||||
sql/format))))
|
sql/format))))
|
||||||
|
|
||||||
|
(deftest test-operators
|
||||||
|
(testing "in"
|
||||||
|
(doseq [[cname coll] [[:vector []] [:set #{}] [:list '()]]]
|
||||||
|
(testing (str "with values from a " (name cname))
|
||||||
|
(let [values (conj coll 1)]
|
||||||
|
(is (= ["SELECT * FROM customers WHERE (id in (1))"]
|
||||||
|
(sql/format {:select [:*]
|
||||||
|
:from [:customers]
|
||||||
|
:where [:in :id values]}))))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue