Fork me on GitHub
#datomic
<
2024-02-29
>
cch116:02:33

Short of a custom transaction function, is anybody aware of a way to retract a datom only if the current value is X? Effectively, I'm looking for a combination of :db/cas and :db/retract....

favila18:02:19

feature request

favila18:02:36

[:db/cas id attr old-val nil] should be legal

favila18:02:49

You could hack this maybe:

favila18:02:08

[:db/cas id attr old-val old-val] [:db/retract db attr old-val]

😢 1
favila18:02:21

i.e. a no-op cas just as a precondition, then retract

favila18:02:49

however, the retract inherently won’t do anything if old-val is no longer asserted, so this is just picking between whether you want the transaction to succeed or fail--the end result by itself should be the same.

cch119:02:20

That's a pretty good hack for my use case. Thanks again, @U09R86PA4.

Vincent01:03:52

Can branching conditionals be done at all at this layer?

Ivar Refsdal08:03:18

Can you write a custom tx function for cloud? (I am not sure what that would look like personally. I've done some work for making it easier to write tx functions for on-prem)

cch113:03:40

Yes -and that's a reasonable fallback too.