datomic 2026-03-19

What is the most idiomatic way to write a query that joins two entities and returns them in one "bucket"? For example, let's say I want to return all nodes in a tree that match some criterion, and their parents:

[:find [?node ...]
 :in $ ?type
 :where
  [?node :node/type ?type]
  [?node :node/parent ?parent]]
I want to return the union of matching ?node and ?parent values, ideally in a single collection. Can I do this with a subquery? With or ?

I've used rules with multiple inputs for this. Easy-peasy.

i believe this is a pull

i'm on my phone or i'd pull up the docs for you

I want a set of entity ids, not maps. I don't think you can do this with pull.

👍 1

(of course I could get the maps and pull out the entity IDs after ... but I'm wondering if there is some way to do this directly in the query.)

Maybe a recursive rule?

(Or rule with multiple impls)

@enn d/index-range against heterogeneous tuple :node/type+parent – essentially an index on type + parent. Are you only looking for immediate descendants of that specific parent, or a recursive tree? d/pull can do recursive queries as Noah said.