Parameter queries in Datomic
Question
I am learning about Datomic queries and was curious about how to do "parameter queries."
This 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 it, or is there a more more concise / idiomatic way of accomplishing the above?
Solution
The answer is in the section "Advanced Queries" of the Datomic tutorial
Use the :in
clause
(d/q '[:find ?n ?x :in $ ?x :where [?n :likes ?x]]
[['ethel :likes "sushi"]['fred :likes "pizza"]] "sushi")
=> #<HashSet [[ethel "sushi"]]>
:in $ ?x
is the parameter clause and the trailing "sushi"
is bound to ?x
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow