3
Datomic의 최신 트랜잭션으로 수정/생성/삭제 된 엔티티의 ID를 찾는 방법을 알고 싶습니다. 어떻게해야합니까?Datomic에서 마지막 트랜잭션의 엔티티 ID를 찾으십니까?
Datomic의 최신 트랜잭션으로 수정/생성/삭제 된 엔티티의 ID를 찾는 방법을 알고 싶습니다. 어떻게해야합니까?Datomic에서 마지막 트랜잭션의 엔티티 ID를 찾으십니까?
이러한 종류의 읽기 패턴 (시간 기반)의 경우 Log API을 사용하는 것이 좋습니다. 참고 :
은 샘플 구현의 :
이(defn affected-entities
"Given a Datomic connection, returns the set of entity ids that were affected
by the last transaction (in e position), excluding the entity representing the
transaction itself."
[conn]
(let [db (d/db conn)]
(->>
(d/q '[:find [?e ...] :in ?log ?t1 ?t2 :where
[(tx-ids ?log ?t1 ?t2) [?tx ...]] ;; binds the last tx
[(tx-data ?log ?tx) [[?e]]]]
(d/log conn) (d/basis-t db) (d/next-t db))
;; filtering out the transaction entity
(remove (fn [eid]
(->> eid d/part (d/ident db) (= :db.part/tx))))
set)))
당신이 사용할 수있는 ['datomic.api/history'] (http://docs.datomic.com/clojure/index.html#datomic.api/ 역사). –