在查询中使用 Datomic pull
Using the Datomic pull in a Query
根据 Datomic 附带的 'geting-started.clj' 文件的第 54 行(在 samples/seattle 下),我应该能够像这样在查询中使用 pull 函数:
(def pull-results (q '[:find (pull ?c [*]) :where [?c :community/name]] (db conn)))
但是,在我下面的代码中出现错误:IllegalArgumentException Argument [*] in :find is not a variable datomic.query/validate-query (query.clj:315)
(defn get-tag [] (d/q '[:find (d/pull ?e [*])
:where [?e :tag.tag/term]] (db conn)))
现在,在我看来,这两个结构相似。再加上从 http://docs.datomic.com/clojure/#datomic.api/pull 读取的拉函数 api 似乎是:
(pull db pattern eid)
我会说 API 自西雅图代码编写以来已经发生了变化。我对么?如果不是,这里发生了什么。谢谢
正如评论者所指出的,问题在于传递了 datomic.api/pull
函数而不是使用 pull 表达式。澄清几点:
您不是在查询中调用 pull
函数,而是使用一个名为 pull
expression inside a find
clause. Note that query accepts a data structure literal (why you have to use quote
/'
). The pull
expression is part of the query grammar 的特殊表达式和数据记录解析器识别的东西,而不是直接调用Datomic API 中的 pull 函数具有不同的调用。
根据 Datomic 附带的 'geting-started.clj' 文件的第 54 行(在 samples/seattle 下),我应该能够像这样在查询中使用 pull 函数:
(def pull-results (q '[:find (pull ?c [*]) :where [?c :community/name]] (db conn)))
但是,在我下面的代码中出现错误:IllegalArgumentException Argument [*] in :find is not a variable datomic.query/validate-query (query.clj:315)
(defn get-tag [] (d/q '[:find (d/pull ?e [*])
:where [?e :tag.tag/term]] (db conn)))
现在,在我看来,这两个结构相似。再加上从 http://docs.datomic.com/clojure/#datomic.api/pull 读取的拉函数 api 似乎是:
(pull db pattern eid)
我会说 API 自西雅图代码编写以来已经发生了变化。我对么?如果不是,这里发生了什么。谢谢
正如评论者所指出的,问题在于传递了 datomic.api/pull
函数而不是使用 pull 表达式。澄清几点:
您不是在查询中调用 pull
函数,而是使用一个名为 pull
expression inside a find
clause. Note that query accepts a data structure literal (why you have to use quote
/'
). The pull
expression is part of the query grammar 的特殊表达式和数据记录解析器识别的东西,而不是直接调用Datomic API 中的 pull 函数具有不同的调用。