diff --git a/CHANGES.md b/CHANGES.md index 5d56d54..08fb39f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## 0.5.3 In development +* Apply seq to sets when converting to sql (@dball) * Support locking selects (@dball) * Add sql array type and reader literal (@loganmhb) diff --git a/src/honeysql/format.clj b/src/honeysql/format.clj index 192e22b..4687013 100644 --- a/src/honeysql/format.clj +++ b/src/honeysql/format.clj @@ -320,6 +320,9 @@ (if *subquery?* (paren-wrap sql-str) sql-str))) + clojure.lang.IPersistentSet + (-to-sql [x] + (-to-sql (seq x))) nil (-to-sql [x] "NULL") SqlParam diff --git a/test/honeysql/core_test.clj b/test/honeysql/core_test.clj index b465411..235586e 100644 --- a/test/honeysql/core_test.clj +++ b/test/honeysql/core_test.clj @@ -80,3 +80,13 @@ (columns :bar) (values [[(honeysql.format/value {:baz "my-val"})]]) 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]}))))))))