Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter queries in Datomic

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?

like image 507
noahlz Avatar asked Aug 09 '12 20:08

noahlz


People also ask

What is a Datalog query?

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.

What is Datalog program?

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.

Is Datomic fast?

Because Datomic queries run in application process space, they can be faster than any possible RPC query in some circumstances.


1 Answers

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

like image 81
noahlz Avatar answered Oct 01 '22 10:10

noahlz