Merge pull request #205 from visibletrap/remove-nil-pred-from-and

Remove nil predicate from :and
This commit is contained in:
Michael Blume 2018-02-19 21:39:09 -08:00 committed by GitHub
commit 36a40bc67c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -423,9 +423,11 @@
"not" (str "NOT " (format-predicate* (first args)))
("and" "or" "xor")
(paren-wrap
(string/join (str " " (string/upper-case op-name) " ")
(map format-predicate* args)))
(->> args
(remove nil?)
(map format-predicate*)
(string/join (str " " (string/upper-case op-name) " "))
(paren-wrap))
"exists"
(str "EXISTS " (to-sql (first args)))

View file

@ -84,7 +84,7 @@
[m pred logic-op]))
(defn where [& args]
(let [[m pred] (prep-where (remove nil? args))]
(let [[m pred] (prep-where args)]
(if (nil? pred)
m
(assoc m :where pred))))

View file

@ -168,3 +168,9 @@
{:values [[1 2] [3 4] [5 6]]}]]}
:parameterizer :none)
["WITH bar (spam, eggs) AS (VALUES (1, 2), (3, 4), (5, 6)) SELECT foo FROM bar1 UNION SELECT foo FROM bar2"]))))
(deftest where-and
(testing "should ignore a nil predicate"
(is (= (format {:where [:and [:= :foo "foo"] [:= :bar "bar"] nil]}
:parameterizer :postgresql)
["WHERE (foo = $1 AND bar = $2)" "foo" "bar"]))))