Skip to content

Instantly share code, notes, and snippets.

@benkamphaus
Created October 6, 2017 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benkamphaus/94af89e680ef9220549494d8f4f5bde9 to your computer and use it in GitHub Desktop.
Save benkamphaus/94af89e680ef9220549494d8f4f5bde9 to your computer and use it in GitHub Desktop.
Group all facts from a history DB for an entity in Datomic by transaction, using sorted map to order.
(require '[datomic.api :as d])
;; for a particular entity, find it's entire tx history
(defn e->tx-history [db ent-id]
(->> (d/datoms (d/history db) :eavt ent-id)
(map (fn [[e a v tx assert]]
[e
(-> db (d/pull '[:db/ident] a) :db/ident)
v
tx
assert]))
(group-by #(nth % 3))
(into (sorted-map))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment