How to find entities with one of several attributes in Datomic

74 views Asked by At

This seemed like a use case for an or clause:

'[:find ?e1
  :where (or [?e1 :a ?e2]
             [?e1 :b ?e2]
             [?e1 :c ?e2])
         [?e2 :x "X"]]

But it fails with Unable to resolve symbol: ?e1 in this context.

2

There are 2 answers

0
estolua On BEST ANSWER

Turns out I was just using an outdated version, or-clauses were introduced in 0.9.5130.

0
adamneilson On

Something like this should work

(let [rules '[(orclause ?e1 ?e2) [?e1 :a ?e2]
              (orclause ?e1 ?e2) [?e1 :b ?e2]
              (orclause ?e1 ?e2) [?e1 :c ?e2]]
      dbval (d/db conn)]
  (d/q '[:find ?e1
         :in $ ?e2 %
         :where (orclause ?e1 ?e2)]
       dbval "X" rules))