Fork me on GitHub
#datomic
<
2022-01-13
>
kenny16:01:03

Can I :find the count of all unique combinations of my :find vars? e.g., In :find ?name ?duration, I want the query to return the count of all unique [?name ?duration] tuples.

👀 1
favila16:01:06

if you’re on-prem, just count the result of the query. There’s no overhead vs doing the count in the query

✔️ 1
favila16:01:41

if you’re client or cloud: :where [(tuple ?name ?duration) ?name+duration] :find (count ?name+duration)

1
kenny18:01:33

tuple is the magic I was looking for. Thank you.

prnc17:01:43

Datomic Cloud: Is the :db.unique/identity & upsert behaviour different for composite tuples? For a unique :my-id I can transact this multiple times:

(d/transact conn {:tx-data [{:my-id #uuid "cffeaaf9-861c-4aee-857f-dd0d704aa608"}]})
But not...
(d/transact conn {:tx-data [{:x 101155069823622
                             :y "bar"}]})
For unique :x+y tuple. Seeing Unique conflict: :x+y, value: ...

favila18:01:30

To use a composite tuple with upsert effectively, you need to assert the new composite yourself

favila18:01:02

Tempid resolution happens before composite-tuple value updating

prnc18:01:22

So in the example above, would need to add :x+y e.g.

{:x 101155069823622
 :y "bar"
 :x+y [101155069823622 "bar"]}
?

prnc18:01:07

Awesome, thanks, will check if that works fine!

prnc18:01:20

If that’s the case, this sentence “Composite attributes are entirely managed by Datomic–you never assert or retract them yourself.” (https://docs.datomic.com/cloud/schema/schema-reference.html#composite-tuples) might be a bit confusing? It did threw me off. Maybe just a misunderstanding on my part.

favila18:01:52

This is an edge case

favila18:01:02

normally, that’s right. identity messes that up

favila18:01:26

Cognitect can speak to whether they think it’s a bug

prnc18:01:30

Thanks for clarifying 🙏 I just mentioned the docs, because they put me on the wrong track 😉 Good to know about the edge case!