Fork me on GitHub
#datomic
<
2020-02-08
>
bbloom23:02:51

i’m curious what kinds of patterns folks do around making tx-data, especially with respect to uniqueness and upserts

bbloom23:02:52

it seems like upserts are mostly automatic when you have like {:unique-kw :a, :x 1} and then later do {:unique-kw :a, :x 2}

bbloom23:02:12

i’d love for the same magic when working with tuples. for example, if you were modeling a two-level hierarchy with uniqueness within each branch of the hierarchy: {:top/name :x} and {:bottom/parent [:top/name :x] :bottom/name :y}

bbloom23:02:40

if you do that, but you have unique/identity on :bottom/parent+name tuple, you get a uniqueness constraint violation when trying to upsert a bottom entity

bbloom23:02:55

something like Unique conflict: :bottom/parent+name, value: [12345 :y] already held by: …. asserted for: …

bbloom23:02:24

i could create some kind of upsert-by database transaction function, but i’m wondering if folks with more datomic experience have examples, suggestions, ideas, patterns, whatever

bbloom23:02:00

ooh, hmm, didn’t realize i could actually add derived tuples as tx data, seems like that works just like a non-tuple attribute for upserts…. that’s nice!

bbloom23:02:55

or maybe this doesn’t work? i probably shouldn’t slack & code at the same time…

bbloom23:02:09

having discovered that - i’m still open to hearing about patterns folks use for building transactions, etc

matthavener16:02:38

I’ve used functions that transform transactions to resolve tempids or de-dup upserts to merge data (pre tuples and for other types of uniqueness not supported by datomic). I’m interested in what you find, because it’s a problem I run into a lot

bbloom02:02:26

i’m curious if you could say more, b/c that’s basically my current plan: to create a richer language on top of tx-data that basically compiles down to tx-data

bbloom02:02:57

basically, a series of statements that are executed and, as a side effect, return tx data

bbloom02:02:27

and a big ol’ multi-method to add “macros” of sorts to that language