我learning about Datomic queries并对如何进行“参数查询”感到好奇。
这就是我提出的:
(d/q '[:find ?n ?x :where [?n :likes ?x] [(= ?x "pizza")]]
[['ethel :likes "sushi"]['fred :likes "pizza"]])
=> #<HashSet [[fred "pizza"]]>
这是它,还是有更简洁/惯用的方法来实现上述目标?
答案 0 :(得分:6)
使用:in
子句
(d/q '[:find ?n ?x :in $ ?x :where [?n :likes ?x]]
[['ethel :likes "sushi"]['fred :likes "pizza"]] "sushi")
=> #<HashSet [[ethel "sushi"]]>
:in $ ?x
是参数子句,尾随"sushi"
绑定到?x