This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-11
Channels
- # announcements (1)
- # asami (10)
- # aws (36)
- # babashka (1)
- # beginners (32)
- # biff (13)
- # calva (2)
- # cider (2)
- # clj-kondo (3)
- # cljs-dev (5)
- # clojure-poland (2)
- # clojured (5)
- # clojurescript (7)
- # core-logic (13)
- # core-matrix (2)
- # core-typed (1)
- # datomic (1)
- # fulcro (19)
- # gratitude (6)
- # meander (15)
- # minecraft (4)
- # pathom (3)
- # podcasts-discuss (2)
- # reagent (19)
- # releases (1)
- # shadow-cljs (69)
- # sql (3)
- # tools-deps (22)
- # vim (1)
Here’s an observation, not sure if it’s even interesting. So next.jdbc has some good documentation on how to work with pg jsonb. But, all the examples sort of assume that you’re only storing non-scalar values, because the examples rely on metadata to pass values back and forth. I had to fight this just a bit because we have some columns where we store scalar values as jsonb (don’t ask wh 🙂 I worked around it in perhaps not the prittiest way, but, I though it was worth metioning. Eg for reading I ended up with this little bit of code:
(defn- <-pgobject
"Transform PGobject containing `json` or `jsonb` value to Clojure
data."
[^org.postgresql.util.PGobject v]
(let [type (.getType v)
value (.getValue v)]
(if (#{"jsonb" "json"} type)
(when value
(let [json-value (<-json value)]
(cond-> json-value
(instance? clojure.lang.IMeta json-value)
(with-meta {:pgtype type}))))
value)))
So basically checking if parsed json value supports metadata.I was just about to post a question about this thanks