This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-24
Channels
- # announcements (6)
- # beginners (89)
- # calva (75)
- # cider (37)
- # clj-kondo (1)
- # cljs-dev (19)
- # cljsjs (8)
- # clojars (1)
- # clojure (122)
- # clojure-europe (6)
- # clojure-italy (41)
- # clojure-nl (18)
- # clojure-uk (24)
- # clojurescript (26)
- # cursive (6)
- # data-science (5)
- # datomic (51)
- # emacs (28)
- # fulcro (8)
- # graalvm (13)
- # hoplon (1)
- # immutant (1)
- # jobs (3)
- # joker (1)
- # keechma (43)
- # lambdaisland (1)
- # leiningen (37)
- # midje (1)
- # nrepl (2)
- # off-topic (32)
- # re-frame (3)
- # reagent (24)
- # reitit (5)
- # remote-jobs (1)
- # shadow-cljs (33)
- # sql (7)
- # tools-deps (11)
hello, all! i am learning datomic as am unsure how to work with :db.cardinality/many
relationships when adding new entities to the collection. e.g.: i have a rule entity that can have multiple :rule/executions (a ref type). from time to time i have to add a new execution to the list. what is the appropriate way of doing it?
one option would be to create an attribute :execution/rule instead of :rule/executions and create new independent executions when necessary. but i am not sure how to do it when i have :rule/executions…
If you are just looking how to transact it, something like this should work:
[[:db/add existing-rule-id :rule/executions "new-exec"]
{:db/id "new-exec"
:exec/attribute :some-value
:exec/another 123
...}]
So you just add a new ref (here temp-id "new-exec"
) to the :db.cardinality/many
attribute (`:rule/executions` in your case). And in same transaction, define that new execution entity as map with correct :db/id
.Although you have many relationship for an attribute, you can “append” new refs as “single value” for the attribute.
also watch out for if you need an ordered :many relationship. this is not automatic and non-trivial currently in Datomic
nice, thanks for the answers!
is anyone aware of a library that can convert a raw datum to its symbolic/transaction form given a dbval? bonus for resolving its :db/id to a any unique-identity attributes on the corresponding entity
sure something like: #datum [1010101 2323232 454545 626262 true] -> [[:some/unique-identity "human-readable-id"] :some/rel-attr [:some/other-unique-identity "also-human-readable"] 626262 true]
.. and am in a situation where i need to see the “diff” that was applied in a human readable form so i can understand what’s going on
I think because it's hard to come up with a universal solution, and it's not very hard to roll your own
and making a list of fns that take db and eid and return either nil or some other representation
(map (fn [[e a v tx op] ((some-fn unique-attr1 unique-attr2 d/ident #(do %2)) db-after e)) ,,,))
this reminds me, is something like this possible in datomic?
'{:find [?e ?es ?v]
:in [$ [?es ...]]
:where [[?e ?es ?v]]}
i was thinking you could query out the ids of all the unique-attrs and pass them there as ?es