Improve null handling on more db helpers

This commit is contained in:
Andrey Antukh 2022-12-07 14:43:35 +01:00
parent d584ae5a0f
commit d768711caa

View file

@ -442,22 +442,25 @@
(defn inet (defn inet
[ip-addr] [ip-addr]
(doto (org.postgresql.util.PGobject.) (when ip-addr
(.setType "inet") (doto (org.postgresql.util.PGobject.)
(.setValue (str ip-addr)))) (.setType "inet")
(.setValue (str ip-addr)))))
(defn decode-inet (defn decode-inet
[^PGobject o] [^PGobject o]
(if (= "inet" (.getType o)) (when o
(.getValue o) (if (= "inet" (.getType o))
nil)) (.getValue o)
nil)))
(defn tjson (defn tjson
"Encode as transit json." "Encode as transit json."
[data] [data]
(doto (org.postgresql.util.PGobject.) (when data
(.setType "jsonb") (doto (org.postgresql.util.PGobject.)
(.setValue (t/encode-str data {:type :json-verbose})))) (.setType "jsonb")
(.setValue (t/encode-str data {:type :json-verbose})))))
(defn json (defn json
"Encode as plain json." "Encode as plain json."