【问题标题】:Datomic query - find all records (entities) with value原子查询 - 查找所有具有值的记录(实体)
【发布时间】:2022-11-07 20:19:11
【问题描述】:

询问:

(d/q '[:find [?e ...] 
       :in $ ?value 
       :where [?e _ ?value]] 
      db "Germany")

什么都不返回,而:

(d/q '[:find [?e ...] 
       :in $ ?value 
       :where [?e :country/name ?value]] 
      db "Germany")

按预期返回实体列表。

_ 不应该用作任何属性名称的通配符并返回包含值的所有内容吗?

我读了这个Datomic query: find all entities with some value,但不知道如何将实际值作为参数。

Datomic 版本:datomic-pro-0.9.5966

【问题讨论】:

    标签: datomic


    【解决方案1】:

    我想出了这种肮脏、耗时的方法,但它确实有效:

    (defn all-by-value
     [db value]
     (reduce
      (fn [res ident]
        (try
          (->> (d/q '[:find [?e ...] :in $ ?a ?v :where [?e ?a ?v]] db ident value)
               (map #(d/entity db %)
               (concat res))
          (catch Exception _ res)))
      [] (d/q '[:find [?e ...] :where [?e :db/ident]] db)))
    

    希望你们中的一些人会发现它有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多