From d768711caae6bc18e828b92885bc9b3e65bcdb46 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 7 Dec 2022 14:43:35 +0100 Subject: [PATCH] :sparkles: Improve null handling on more db helpers --- backend/src/app/db.clj | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index 9848a943a..6e4d12061 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -442,22 +442,25 @@ (defn inet [ip-addr] - (doto (org.postgresql.util.PGobject.) - (.setType "inet") - (.setValue (str ip-addr)))) + (when ip-addr + (doto (org.postgresql.util.PGobject.) + (.setType "inet") + (.setValue (str ip-addr))))) (defn decode-inet [^PGobject o] - (if (= "inet" (.getType o)) - (.getValue o) - nil)) + (when o + (if (= "inet" (.getType o)) + (.getValue o) + nil))) (defn tjson "Encode as transit json." [data] - (doto (org.postgresql.util.PGobject.) - (.setType "jsonb") - (.setValue (t/encode-str data {:type :json-verbose})))) + (when data + (doto (org.postgresql.util.PGobject.) + (.setType "jsonb") + (.setValue (t/encode-str data {:type :json-verbose}))))) (defn json "Encode as plain json."