Parameter Requests in Datomic

I learned about Datomic queries , and I was curious how to perform "parameter queries."

Here is what I came up with:

(d/q '[:find ?n ?x :where [?n :likes ?x] [(= ?x "pizza")]] 
  [['ethel :likes "sushi"]['fred :likes "pizza"]])

=> #<HashSet [[fred "pizza"]]>

Is this or is there a more concise / idiomatic way of doing the above?

+5
source share
1 answer

The answer is in the Advanced Queries section of the Datomic tutorial

Use offer :in

(d/q '[:find ?n ?x :in $ ?x :where [?n :likes ?x]] 
  [['ethel :likes "sushi"]['fred :likes "pizza"]] "sushi")

=> #<HashSet [[ethel "sushi"]]>

:in $ ?xis a sentence of the parameter, and the final one is "sushi"tied to?x

+6
source

All Articles