Recursive query?

I have a query:

 '[:find (pull ?p [*])
     :in $ ?m ?t
     :where [?p :msr/msrs ?m]
     [?t :type/msrs ?p]]

Give me the measures that match m, but only if they have a match entry in type. It works, but measures can own other measures, and I want to pull those parent measures as well.

There might even be grandparents I need to pull. Just wondering if there’s an elegant way to do this. Or even an inelegant way. (My other thought is to pull them all, regardless of parentage and then filter out the unwanted ones after the fact.)

You can use datalog rules to define a recursive query.

An example using the mbrainz dataset: https://github.com/Datomic/mbrainz-sample/blob/master/src/clj/datomic/samples/mbrainz/rules.clj#L37

There was also some prior discussion of this topic here: How to do graph traversal with rules (with a couple additional examples)

1 Like

Thanks, Marhsall.