2017-02-24 1 views

답변

2

이러한 종류의 읽기 패턴 (시간 기반)의 경우 Log API을 사용하는 것이 좋습니다. 참고 :

  1. 마지막 트랜잭션의 영향을받은 엔티티가 둘 이상있을 수 있습니다.
  2. 실제로 트랜잭션 자체는 해당 트랜잭션에 대해 생성 된 엔티티로 표시되므로 결과에서 제외 할 수 있습니다. 여기

은 샘플 구현의 :

(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))) 
관련 문제