Fork me on GitHub

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


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}


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}


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


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


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


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!


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


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


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


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


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


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