2017-02-24 9 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))) 
関連する問題