This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-22
Channels
- # announcements (7)
- # babashka (17)
- # beginners (45)
- # biff (2)
- # cider (16)
- # clj-on-windows (3)
- # cljs-dev (12)
- # clojure (27)
- # clojure-austin (1)
- # clojure-europe (18)
- # clojure-norway (5)
- # clojurescript (36)
- # conjure (35)
- # core-async (2)
- # datascript (4)
- # datomic (4)
- # emacs (15)
- # fulcro (23)
- # holy-lambda (12)
- # hyperfiddle (1)
- # introduce-yourself (5)
- # nbb (11)
- # off-topic (37)
- # pathom (34)
- # pedestal (9)
- # reitit (4)
- # releases (1)
- # remote-jobs (1)
- # sci (5)
- # scittle (3)
- # shadow-cljs (88)
- # tools-build (4)
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.)
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.