2

假设我有一个具有多值属性(例如数字)的 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"。

谢谢!

4

1 回答 1

3

:cardinality/manydatomic 中的值仍然作为单独的值存储在幕后。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"用于数据库中所有事实的值。

于 2015-03-05T04:55:27.673 回答