This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-26
Channels
- # asami (5)
- # babashka (9)
- # beginners (19)
- # calva (14)
- # cider (13)
- # clj-kondo (9)
- # cljfx (2)
- # clojure (51)
- # clojure-bay-area (1)
- # clojure-europe (26)
- # clojurescript (23)
- # code-reviews (7)
- # core-async (1)
- # datahike (4)
- # datalevin (3)
- # emacs (2)
- # kaocha (2)
- # malli (6)
- # nrepl (3)
- # polylith (3)
- # re-frame (15)
- # reveal (1)
- # shadow-cljs (13)
- # tools-deps (6)
say I have this collection of links to other entities like above. what's the best way for me to add those to the db as actual refs to the nodes?
i.e. right now I add the string above, which I presume is a :db/ident
that I can use in a query later. I'd rather have an actual ID of the node so that I can use it in first position in queries as well as use graphing capabilities.
I could look up the node by ident before transacting. is that the best way?
I think I can understand your questions, so I’ll try to answer… The best way? Well, internally, the transaction needs to get the node id for the entity, so that this can go into the “subject” or “entity” position of a transacted triple. That can either be done by looking it up beforehand, or by including it in the transaction, by something like:
{:db/id [:db/ident "my-identifier] ...}
Whether you use a transaction syntax to do it, or if you do it yourself, the lookup is still needed. What’s “best” is probably to do it in the transaction, since there’s probably less round-trip overhead compared to your 2 calls.
There’s also the (tiny) possibility of a race condition if you look it up yourself.