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/歴史)。 –