This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Is it possible to write queries like this?
(xt/q (xt/db node) '{:find [?e ?k ?v]
:in [[?k ...]]
:where [[?e ?k ?v]]}
[:key1 :key2 :key3])
Not sure how different datalog queries in xtdb are from datomic, but this works in datomic at least:
(d/q '[:find ?e ?a ?v
:in $ [?a ...]
:where
[?e ?a ?v]]
app-db
[:key1 :key2])
Mucho loves @U9MKYDN4Q 😛
If I'm not mistaken, you cannot have the ?k
variable in XT's Datalog. It needs to be specified ahead of time.
(xt/q (xt/db node)
'{:find [?e ?v]
:where [(or [?e :key1 ?v]
[?e :key2 ?v]
[?e :key3 ?v])]})
Yep. But your original example also does. (If I'm not mistaken, your query and my query are equivalent.)
It is one of the shortcomings of XT's Datalog. I've always been able to get around it, though.
Right. I did say in the next comment underneath the parent of this thread I don’t know the value of ?k ahead of time 🙂
For completeness, if the key is truly unknown ahead of time, there's a way through the attribute-stats
https://juxt-oss.zulipchat.com/#narrow/stream/194466-xtdb-users/topic/reverse.20references.3F/near/255741555.
this was a hack, never tested thoroughly...but might be useful if you really want something dynamic https://gist.github.com/refset/93135adcbf41fccab9b641638ab10997