【发布时间】:2015-10-17 00:27:45
【问题描述】:
我正在使用 Datomic,并希望根据我的查询从任意数量的时间点提取整个实体。如果我在执行查询之前知道这些实例,Datomic 文档有一些关于如何从两个不同的数据库实例执行查询的不错示例。但是,我希望我的查询确定我需要的“as-of”类型数据库实例的数量,然后在提取实体时使用这些实例。到目前为止,这是我所拥有的:
(defn pull-entities-at-change-points [entity-id]
(->>
(d/q
'[:find ?tx (pull ?dbs ?client [*])
:in $ [?dbs ...] ?client
:where
[?client ?attr-id ?value ?tx true]
[(datomic.api/ident $ ?attr-id) ?attr]
[(contains? #{:client/attr1 :client/attr2 :client/attr3} ?attr)]
[(datomic.api/tx->t ?tx) ?t]
[?tx :db/txInstant ?inst]]
(d/history (d/db db/conn))
(map #(d/as-of (d/db db/conn) %) [1009 1018])
entity-id)
(sort-by first)))
我正在尝试查找其中 :client 实体上的某些属性发生更改的所有事务,然后将实体拉出,因为它在这些时间点存在。这条线:(map #(d/as-of (d/db db/conn) %) [1009 1018]) 是我尝试在两个特定事务中创建一系列数据库实例,我知道客户端的属性发生了变化。理想情况下,我想在一个查询中完成所有这些操作,但我不确定这是否可能。
希望这是有道理的,但如果您需要更多详细信息,请告诉我。
【问题讨论】:
标签: clojure jvm datomic datalog