Fork me on GitHub
#datomic
<
2019-06-24
>
Matheus Moreira09:06:33

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?

Matheus Moreira09:06:37

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…

snurppa09:06:50

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.

snurppa09:06:21

Although you have many relationship for an attribute, you can “append” new refs as “single value” for the attribute.

steveb8n11:06:09

also watch out for if you need an ordered :many relationship. this is not automatic and non-trivial currently in Datomic

Matheus Moreira16:06:25

nice, thanks for the answers!

spieden17:06:33

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

ghadi17:06:24

what is a "symbolic/transaction form"?

spieden17:06:52

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]

spieden17:06:05

basically find idents for the e/a/v numeric ids

favila17:06:41

there's not going to be a universal way to do that

spieden17:06:03

for the unique-identity attrs you mean?

spieden17:06:21

sure, there can be ambiguity there

favila17:06:27

for the A it's just (d/ident db-after a)

favila17:06:02

but attrs don't necessarily need to be named

spieden17:06:34

this is just for debugging the result of applying a transaction

spieden17:06:53

i generate big ones and let datomic prune the redundant stuff for me

spieden17:06:13

.. 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

favila17:06:14

If there's an attr you have in mind you can try to resolve it specifically

favila17:06:44

anyway short answer is no, I'm aware of no lib

favila17:06:02

I think because it's hard to come up with a universal solution, and it's not very hard to roll your own

spieden17:06:02

ok i might make a best effort general one

spieden17:06:14

there are enough different kinds of entities floating around

spieden17:06:40

.. and the relations are a big part of it

favila17:06:24

in my mind I am imagining mapping some-fn over E A V

favila17:06:53

and making a list of fns that take db and eid and return either nil or some other representation

favila17:06:01

bottom out with the eid itself (or maybe even the tempid)

favila17:06:39

(map (fn [[e a v tx op] ((some-fn unique-attr1 unique-attr2 d/ident #(do %2)) db-after e)) ,,,))

spieden17:06:52

yeah that makes sense

favila17:06:58

one for each EAV of course

spieden17:06:06

this reminds me, is something like this possible in datomic?

'{:find  [?e ?es ?v]
  :in    [$ [?es ...]]
  :where [[?e ?es ?v]]}

ghadi17:06:32

better to use the datoms API for that

favila17:06:06

just because of result size

spieden17:06:18

i was thinking you could query out the ids of all the unique-attrs and pass them there as ?es

spieden17:06:24

oh yeah, i would constrain in more

favila17:06:44

you can feed the entire result in, implement the some-fn thing with rules

favila17:06:30

you'll get duplicates if they match multiple ways

favila17:06:46

but, you can include an index per datom too, then group-by the result

favila17:06:55

so, it's like seeing all possibilites at once

spieden17:06:19

yeah that would be fine for just making something legible

spieden17:06:57

cool thanks for the advice guys

PB20:06:12

I am about to import ~2m file entities into datomic that are all a component of different companies. Is it best practice to partition by "company" or by "file"?

PB20:06:40

Or is there another option I hadn't considered