Make 'format' ignore all keys in the map with 'nil' as their value.

This commit is contained in:
Thomas Athorne 2014-08-04 15:08:16 +01:00
parent 753cff8374
commit 53d5185173
2 changed files with 5 additions and 2 deletions

View file

@ -247,7 +247,7 @@
(-to-sql [x] (.s x)) (-to-sql [x] (.s x))
clojure.lang.IPersistentMap clojure.lang.IPersistentMap
(-to-sql [x] (let [clause-ops (concat (-to-sql [x] (let [clause-ops (concat
(filter #(contains? x %) clause-order) (filter #(and (contains? x %) (get x %)) clause-order)
(remove known-clauses (keys x))) (remove known-clauses (keys x)))
sql-str (binding [*subquery?* true sql-str (binding [*subquery?* true
*fn-context?* false] *fn-context?* false]

View file

@ -54,4 +54,7 @@
["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo f, baz b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod c ON f.a = c.d RIGHT JOIN bock ON bock.z = c.e WHERE ((f.a = ? AND b.baz <> ?) OR (1 < 2 AND 2 < 3) OR (f.e in (1, ?, 3)) OR f.e BETWEEN 10 AND 20) GROUP BY f.a HAVING 0 < f.e ORDER BY b.baz DESC, c.quux LIMIT 50 OFFSET 10 " ["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo f, baz b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod c ON f.a = c.d RIGHT JOIN bock ON bock.z = c.e WHERE ((f.a = ? AND b.baz <> ?) OR (1 < 2 AND 2 < 3) OR (f.e in (1, ?, 3)) OR f.e BETWEEN 10 AND 20) GROUP BY f.a HAVING 0 < f.e ORDER BY b.baz DESC, c.quux LIMIT 50 OFFSET 10 "
"bort" "gabba" 2]))) "bort" "gabba" 2])))
(testing "SQL data prints and reads correctly" (testing "SQL data prints and reads correctly"
(is (= m1 (read-string (pr-str m1))))))) (is (= m1 (read-string (pr-str m1)))))
(testing "Keys with value 'nil' are ignored"
(is (= (sql/format {:select '(:a.id) :from '([:foo :a]) :group-by nil :order-by nil})
["SELECT a.id FROM foo a"])))))