在函数中封装Datascript查询?

问题描述 投票:0回答:1

在使用Datascript时遇到了一个看似奇怪的问题。不知为什么,当我运行这个查询时,如果不把它封装在函数中,一切都能正常运行。但是一旦我把它封装在函数中,它就会返回数据库中每个实体的:blockcontent的值。我很困惑,因为过去我在封装其他Datascript查询时没有遇到过任何问题。有比我更有经验的Datascript用户看到了什么问题吗?

;; Works fine and returns the correct value
(ds/q '[:find ?block-text
        :where
        [?id :block/id "l_63xa4m1"]
        [?id :block/content ?block-text]]
      @conn)

;; Returns every value for `:block/content` in the db
(defn content-find
  [id-passed]
  (ds/q '[:find ?block-text
          :where
          [?id :block/id ?id-passed]
          [?id :block/content ?block-text]]
        @conn))
(content-find "l_63xa4m1")

EDIT: 解决了 此处

clojure clojurescript datalog datascript
1个回答
1
投票

在你的 defn 您正在使用的查询子句的版本 [?id :block/id ?id-passed]. 这实际上并没有使用 id-passed 你传递给函数的参数。

我不知道如何正确传递参数。我相信有一个 :in 条款还是什么?

© www.soinside.com 2019 - 2024. All rights reserved.