Fix #221 by treating #inline nil as a special case
This commit is contained in:
parent
077b7f06c6
commit
2b238c5a47
3 changed files with 16 additions and 1 deletions
|
|
@ -1,3 +1,7 @@
|
||||||
|
## 0.9.4 (in progress)
|
||||||
|
|
||||||
|
* `#sql/inline nil` should produce `NULL`. Fix #221. (@seancorfield)
|
||||||
|
|
||||||
## 0.9.3
|
## 0.9.3
|
||||||
|
|
||||||
* Support parameters in `#sql/raw`. Fix #219. (@seancorfield)
|
* Support parameters in `#sql/raw`. Fix #219. (@seancorfield)
|
||||||
|
|
|
||||||
|
|
@ -411,7 +411,10 @@
|
||||||
(str "ARRAY[" (comma-join (map to-sql (.-values x))) "]"))
|
(str "ARRAY[" (comma-join (map to-sql (.-values x))) "]"))
|
||||||
SqlInline
|
SqlInline
|
||||||
(to-sql [x]
|
(to-sql [x]
|
||||||
(str (.-value x)))
|
(let [v (.-value x)]
|
||||||
|
(if (some? v)
|
||||||
|
(str v)
|
||||||
|
"NULL")))
|
||||||
#?(:clj Object :cljs default)
|
#?(:clj Object :cljs default)
|
||||||
(to-sql [x]
|
(to-sql [x]
|
||||||
#?(:clj (add-anon-param x)
|
#?(:clj (add-anon-param x)
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,14 @@
|
||||||
(-> (select :*)
|
(-> (select :*)
|
||||||
(from :foo)
|
(from :foo)
|
||||||
(where [:= :id (sql/inline 5)])
|
(where [:= :id (sql/inline 5)])
|
||||||
|
sql/format)))
|
||||||
|
;; testing for = NULL always fails in SQL -- this test is just to show
|
||||||
|
;; that an #inline nil should render as NULL (so make sure you only use
|
||||||
|
;; it in contexts where a literal NULL is acceptable!)
|
||||||
|
(is (= ["SELECT * FROM foo WHERE id = NULL"]
|
||||||
|
(-> (select :*)
|
||||||
|
(from :foo)
|
||||||
|
(where [:= :id (sql/inline nil)])
|
||||||
sql/format))))
|
sql/format))))
|
||||||
|
|
||||||
#?(:cljs (cljs.test/run-all-tests))
|
#?(:cljs (cljs.test/run-all-tests))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue