Skip to content

Instantly share code, notes, and snippets.

@refset
Created October 15, 2021 12:26
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save refset/8439ceebf3c1f08c614b0c818266a140 to your computer and use it in GitHub Desktop.
entity-history-in-query.clj
(defn get-vt-created [db eid]
(with-open [h (xt/open-entity-history db eid :asc)]
(-> (iterator-seq h)
first
::xt/valid-time)))
(defn get-vt-last-updated [db eid]
(with-open [h (xt/open-entity-history db eid :desc)]
(-> (iterator-seq h)
first
::xt/valid-time)))
(xt/q (xt/db my-node)
'{:find [e vt-created vt-last-updated]
:limit 1
:where [[e :xt/id]
[(dev/get-vt-created $ e) vt-created]
[(dev/get-vt-last-updated $ e) vt-last-updated]]})
;;=> [[-219 #inst "2021-10-15T12:01:06.289-00:00" #inst "2021-10-15T12:15:11.020-00:00"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment