假设我有一个具有多值属性(例如数字)的 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"]
然后返回所有实体,因为查询被解释为 “查找 strs 成员不包含“b”的实体”, 但我需要
“找到每个成员都不包含“b”的实体 e”。
谢谢!
最佳答案
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"])]
这将找到数据库中所有事实的 :strs
值不是 "b"
的所有 ?e
。
关于Datomic 将谓词应用于基数很多的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28868522/