This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-22
Channels
- # adventofcode (12)
- # announcements (6)
- # aws (5)
- # babashka (57)
- # beginners (40)
- # calva (17)
- # clojure-europe (10)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-uk (3)
- # clojuredesign-podcast (4)
- # cursive (3)
- # datomic (9)
- # etaoin (5)
- # fulcro (12)
- # hyperfiddle (42)
- # missionary (2)
- # off-topic (11)
- # reagent (6)
- # scittle (131)
- # squint (3)
- # tools-deps (4)
- # uncomplicate (1)
- # vscode (1)
How do people normally deal with adding/removing namespaces in keys? Say my database has attributes :thing/foo
and :thing/bar
. I am writing a function accepting a db
and a map containing some keys. This map conforms to a spec like (s/keys :req-un [:thing/foo] :opt-un [:thing/bar])
. In Datomic, the attributes are namespaced keys, but the map in the function does not have namespaced keys. So I cannot pass the map directly into d/transact
.
To alleviate this problem, do you write your specs so that the map keys must be qualified? Or do you manually construct the transaction data within the function? e.g.
(d/transact conn
{:tx-data [(update-keys m
(fn [k]
(keyword "thing" (name k))))]})
I don’t like this approach (due to time and effort spent in marshaling data).
Another “bad approach” I have considered, but rejected, is
(let [{:keys [foo bar]} m]
(d/transact conn {:tx-data [#:thing{:foo foo :bar bar}]}))
This will blow up whenever m
does not have :thing/bar
.
So I am wondering if I am missing something obvious or there is a good practice I am simply unaware of.> or there is a good practice I am simply unaware of. namespace all your keys everywhere, not just in your database
https://docs.datomic.com/pro/best-practices.html#group-related-attributes
Ah, I forgot to mention one more thing in my post: whether people just rely on the caller of database-using functions to use namespaced keys
We use namespaced keywords everywhere. all data passed through function (like maps) will have namespaced keywords. It’s less imported for non-domain-specific data however. https://clojure.org/about/spec#_names_are_important https://clojure.org/about/spec#_global_namespaced_names_are_more_important If you have to transform keywords from no-ns to ns (like if you’re consuming a 3rd party API or something), then I would do that early as possible in your application,
(let [m {:foo 1 :bar 2}]
(update-keys m (comp (partial keyword "thing") name)))
It’s also not uncommon to qualify the keywords when decoding another data-format (like json)
(jsonista.core/read-value
"{\"foo\": \"bar\"}"
(jsonista.core/object-mapper
{:decode-key-fn (comp (partial keyword "thing") name)}))
Thanks for the advice! Thankfully for this application I have full control over the stack (Clojure backend, ClojureScript frontend, Datomic as database), so I can use EDN and afford to have namespace-qualified keys everywhere.
Does anyone know whether the NodeDbCount
metric for Datomic Cloud listed on https://docs.datomic.com/cloud/operation/monitoring.html#metrics is new? We've got systems between <tel:995-9204|995-9204> and <tel:1067-9276|1067-9276> and I can't see it in CloudWatch.