How to get a list of changes in Datomic

345 views
Skip to first unread message

rogergl

unread,
Dec 27, 2014, 1:57:51 PM12/27/14
to clo...@googlegroups.com
I would like to replay all changes since a specific timestamp.  It seems as if I can get all transactions with 

(q '[:find ?t :where 
     [_ :db/txInstant ?t]
     ] (db conn))

Using as-of would allow me to replay the state at a given point in time. But that would replay the complete state and not just the changes.

Is it possbile to get just the changes for a specific transaction ?

I tried 

  (q '[:find ?c ?n  :where 
     [?tx :db/txInstant g]
     [?c :db/txInstant ?n ?tx]] (db conn))

to test if I can get back a result for a specific transaction. That did not work although g was a value from the first query.

Regards
  Roger

Ashton Kemerling

unread,
Dec 27, 2014, 3:07:56 PM12/27/14
to clo...@googlegroups.com
I think this conj video covered that. 

http://m.youtube.com/watch?v=7lm3K8zVOdY

--Ashton

Sent from my iPhone
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tj Gabbour

unread,
Dec 28, 2014, 8:10:14 AM12/28/14
to clo...@googlegroups.com

Hi!

If I understand correctly... consider something like the following:

(let [log (d/log (db/conn))
      my-tx 123456789123456]
  (->> (d/tx-range log my-tx (inc my-tx))
       seq
       pprint))

You get a bunch of datoms and transaction ID.

You can access a datom's fields with: :e :a :v :tx :added.

At first, the datoms look depressing because attributes look like 74 instead of :mouse/name. So use(d/ident db 74) to get :mouse/name. (You might like to make a little util which turns these datoms into a nice map or record. Records are nice because they seem to print fields in the :e :a :v :tx :added order you declare.)

FWIW, you may see two datoms where the entities are the same, but :added is different. That's because you changed something; the entity's old value was retracted and the new value was added.

Hope this helps,

 Tj

rogergl

unread,
Dec 28, 2014, 9:18:43 AM12/28/14
to clo...@googlegroups.com
Thanks,

that helped a lot.

Regards
  Roger


Reply all
Reply to author
Forward
0 new messages