How to get date and time of the last transaction in datomic db?

I want to find the most recent transaction associated with a connection. The following doesn't seem to give the correct date:

(require '[datomic.api :as datomic])

(-> conn datomic/db datomic/basis-t datomic/t->tx (java.util.Date.))

      

+3


source to share


3 answers


I understood:



(defn last-transaction-time [db]
  (let [t (-> db datomic/basis-t)]
    [t (ffirst (datomic/q '[:find ?t
                            :in $ ?tx
                            :where [?tx :db/txInstant ?t]]
                          db
                          (datomic/t->tx t)))]))

      

+4


source


You probably want to let

get the result of your stream function before datomic/t->tx

. Then use that to query for a transaction object (an implicitly created object for each transaction). Each transaction object has an attribute :db/txInstant

that is implicitly added during the transaction. The value of this attribute is what you would like to pass to the static method java.util.Date.

.



0


source


It should be much easier

 (d/q
     '[:find (max 1 ?tx)
       :where
       [?tx :db/txInstant]]
     db)

      

0


source







All Articles