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?
Datalog is a deductive query system, typically consisting of: A database of facts. A set of rules for deriving new facts from existing facts. a query processor that, given some partial specification of a fact or rule: finds all instances of that specification implied by the database and rules.
Datalog is a declarative logic programming language. Query evaluation in Datalog is based on first order logic thus, it is sound and complete. A Datalog program includes facts and rules. A rule consists of two elements, the head and the body, separated by the “:-”symbol.
Because Datomic queries run in application process space, they can be faster than any possible RPC query in some circumstances.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With