【问题标题】:Datomic apply predicate to attribute with cardinality manyDatomic 将谓词应用于基数多的属性
【发布时间】:2015-03-05 01:40:07
【问题描述】:

假设我有一个具有多值属性(例如数字)的 Datomic 实体。如何返回其值不包含特定数字的实体列表?

举个例子,

{:db/id #db/id [:db.part/db]
:db/ident :strs
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
db.install/_attribute :db.part/db
}

我想找到列表中不包含数字 1 的所有实体。

If I do something like:
[:find ?e :where 
[?e :strs ?v]
(not [(.contains ?v "b")])
]

但我有

e1 :strs ["a", "b", "c"]
e2 :strs ["a", "b"]
e3 :strs ["h", "i", "j"]

然后返回所有实体,因为查询被解释为 "查找具有不包含 "b" 的 strs 成员的实体", 但我需要

"查找每个成员不包含"b"的实体e"。

谢谢!

【问题讨论】:

    标签: datomic datalog


    【解决方案1】:

    在 datomic 中为 :cardinality/many 的值是 still stored as individual values under the hood。所以你的数据库中e1 的事实是:

    [[e1 :strs "a" tx]
     [e1 :strs "b" tx]
     [e1 :strs "c" tx]]
    

    您可以在查询中利用它:

    '[:find ?e
      :where
      [?e :strs]
      (not [?e :strs "b"])]
    

    这将找到所有?e:strs 值不是"b" 的数据库中的所有事实。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多