Fork me on GitHub
#datomic
<
2022-04-29
>
dazld13:04:15

is there any way to say “add n to a value” multiple times in a transaction, without having to coordinate the real values?

favila13:04:29

No, you have to prepare your tx data differently. Transactions are run and applied atomically: there’s no db to read which ever had only some of your updates but not others

dazld13:04:46

got it, thought it might be like that

dazld13:04:18

i’ll turn it around, and have multiple data supplied to the tx fn, and do the calculation there

dazld13:04:36

ie, if I say that [[:db/add "foo" :some/metric 1] [:db/add "foo" :some/metric 2]...] - i clearly get conflicts. what’s the solution?

dazld13:04:13

if i use a tx fn, it’s the same problem, as it expands to the same tx data - unless I’m missing something?

Linus Ericsson13:04:12

no, you have to do this addition when preparing the tx-data. but consider the possibility to do several transactions as well, they can sometimes be batched.

👍 1
dazld13:04:55

exactly - it’s all ok when calling 1 fn per tx, but in a batch it’s not happy

dazld13:04:04

but - think i see a way out.

enn14:04:39

when I’ve wanted to do something similar I ended up doing a little processing on the accumulated tx-data before actually transacting, to coalesce accretive changes like this.

👍 2
dazld10:04:31

@U060QM7AA in the transactor, or the peer? I’m thinking a tx function that can take multiple items would be the simplest - but this condition that each transaction can only have one of these calls annoys.

enn11:04:56

@U3ZUC5M0R I just did it in the peer.

👍 2