diff --git a/CHANGES.md b/CHANGES.md index 234020f..d12f1ca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## Coming in 0.9.6 + +* Filter `nil` conditions out of `where`/`merge-where`. Fix #246. (@seancorfield) +* Fix reflection warning introduced in 0.9.5 (via PR #237). + ## 0.9.5 * Support JDK11 (update Midje). PR #238. (@camsaul) diff --git a/src/honeysql/format.cljc b/src/honeysql/format.cljc index 079cd07..0568ae2 100644 --- a/src/honeysql/format.cljc +++ b/src/honeysql/format.cljc @@ -79,7 +79,7 @@ ;; Use this function instead of `string/upper-case` as it will always use Locale/US. (def ^:private ^{:arglists '([s])} upper-case ;; TODO - not sure if there's a JavaScript equivalent here we should be using as well - #?(:clj (fn [s] (.. s toString (toUpperCase (java.util.Locale/US)))) + #?(:clj (fn [^String s] (.. s toString (toUpperCase (java.util.Locale/US)))) :cljs string/upper-case)) (defn quote-identifier [x & {:keys [style split] :or {split true}}] diff --git a/src/honeysql/helpers.cljc b/src/honeysql/helpers.cljc index 9a9dced..44cf50c 100644 --- a/src/honeysql/helpers.cljc +++ b/src/honeysql/helpers.cljc @@ -80,7 +80,7 @@ [:and preds]) pred (if (>= 1 (count preds)) (first preds) - (into [logic-op] preds))] + (into [logic-op] (remove nil? preds)))] [m pred logic-op])) (defn where [& args] diff --git a/test/honeysql/core_test.cljc b/test/honeysql/core_test.cljc index f3b9cbf..2627842 100644 --- a/test/honeysql/core_test.cljc +++ b/test/honeysql/core_test.cljc @@ -224,6 +224,11 @@ (sql/format (apply merge-where sqlmap []))))))) (deftest merge-where-test + (is (= ["SELECT * FROM table WHERE (foo = bar AND quuz = xyzzy)"] + (-> (select :*) + (from :table) + (where [:= :foo :bar] [:= :quuz :xyzzy]) + sql/format))) (is (= ["SELECT * FROM table WHERE (foo = bar AND quuz = xyzzy)"] (-> (select :*) (from :table) @@ -231,4 +236,12 @@ (merge-where [:= :quuz :xyzzy]) sql/format)))) +(deftest where-nil-params-test + (testing "where called with nil parameters - see #246" + (is (= ["SELECT * FROM table WHERE (foo = bar AND quuz = xyzzy)"] + (-> (select :*) + (from :table) + (where nil [:= :foo :bar] nil [:= :quuz :xyzzy] nil) + sql/format))))) + #?(:cljs (cljs.test/run-all-tests))