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]
(when ip-addr
(doto (org.postgresql.util.PGobject.) (doto (org.postgresql.util.PGobject.)
(.setType "inet") (.setType "inet")
(.setValue (str ip-addr)))) (.setValue (str ip-addr)))))
(defn decode-inet (defn decode-inet
[^PGobject o] [^PGobject o]
(when o
(if (= "inet" (.getType o)) (if (= "inet" (.getType o))
(.getValue o) (.getValue o)
nil)) nil)))
(defn tjson (defn tjson
"Encode as transit json." "Encode as transit json."
[data] [data]
(when data
(doto (org.postgresql.util.PGobject.) (doto (org.postgresql.util.PGobject.)
(.setType "jsonb") (.setType "jsonb")
(.setValue (t/encode-str data {:type :json-verbose})))) (.setValue (t/encode-str data {:type :json-verbose})))))
(defn json (defn json
"Encode as plain json." "Encode as plain json."