Fork me on GitHub
#datomic
<
2022-07-22
>
jasonjckn08:07:02

I want to fetch any & all ‘movies’ where any one of it’s attributes were changed after t1 , here’s what I came up with…

(def t1 #inst "2022-07-21T07:27:18.190-00:00")


  (d/q '[:find  ?e
         :in $ ?t1
         :where
         [(ground [:movie/id
                   :movie/description
                   :movie/name]) [?a ...]]
         [?e ?a _ ?tx]
         [?tx :db/txInstant ?tx-t]
         [(> ?tx-t ?t1)]]
       *db* t1)
Is this the right approach? Or is there a better way to do this. (Also, should I rely on :db/txInstant in your experience, or reify my own, e.g. an attribute like :record/modified-at , i’ve read this is a good idea not to rely on :db/txInstant, but it’s not immediately obvious to me how to strictly ensure monotonicity if I set it via (java.util.Date.)

favila12:07:05

Use a db with a (d/since db t1) filter applied instead

🙏 1
👍 1
jasonjckn17:07:57

Is this a datomic bug… seems odd behaviour to me…

(<= (clojure.core/inst-ms* (java.util.Date.))
   (clojure.core/inst-ms* (java.time.Instant/now))
   (clojure.core/inst-ms* (java.util.Date.)))
;; always evals => true 



 (d/q '[:find ?t1 ?t2 ?t3
     :in ?t1 ?t2 ?t3
     :where
     [(<= ?t1 ?t2)]
     [(<= ?t2 ?t3)]]
    (java.util.Date.)
    (java.time.Instant/now)
    (java.util.Date.))
;; always evals to => #{}
The issue seems to be that since Instants have no timezone information, Datomic treats the value of Instant as local clock time, when in fact (java.time.Instant/now) returns a UTC time value (without timezone information). If it’s a bug, I can file a bug report, let me know where.