This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-01
Channels
- # announcements (3)
- # aws (1)
- # babashka (56)
- # beginners (42)
- # calva (9)
- # cider (6)
- # circleci (5)
- # clj-kondo (17)
- # cljs-experience (1)
- # cljsjs (2)
- # clojure (106)
- # clojure-australia (1)
- # clojure-europe (36)
- # clojure-germany (5)
- # clojure-italy (13)
- # clojure-nl (14)
- # clojure-spec (19)
- # clojure-uk (27)
- # clojurescript (27)
- # cursive (20)
- # datomic (24)
- # events (2)
- # fulcro (11)
- # graalvm (1)
- # jobs (6)
- # lsp (6)
- # malli (5)
- # meander (36)
- # membrane (17)
- # nbb (4)
- # nextjournal (86)
- # off-topic (18)
- # pathom (3)
- # polylith (5)
- # portal (14)
- # rdf (5)
- # re-frame (5)
- # releases (6)
- # remote-jobs (3)
- # reveal (2)
- # ring (6)
- # shadow-cljs (171)
- # tools-deps (61)
- # vim (10)
- # xtdb (6)
How do I do that?
(d/q '[:find ?e ?contract-end
:in $ ?date
:where
[?e :contract/end ?contract-end]
[(< ?date ?contract-end)]]
conn
(java.util.Date.)))
I am trying to get only entities that have a date that is later than the one passed. But I am getting ClassCastException 😞Just evaluating (< (Date.) (Date.))
in the repl gives a ClassCastException, so no wonder if Datomic does as well.
(def older (Date.))
(d/q '[:find ?contract-end => #{[#inst "2022-02-01T12:56:01.393-00:00"]}
:in $ ?date
:where
[?e :contract/end ?contract-end]
[(> ?date ?contract-end)]]
[[1 :contract/end (Date.)]
[2 :contract/end older]]
(Date.)))
This works, that means there is somewhere a non-inst in the query 🍌@U4GEXTNGZ I think your class cast may be about trying to cast a connection to a db, nothing about dates. Your db var is named conn
which is fishy
no sorry about that... I am using d/db
to get the conn... I am used to use datahike and there usually it's a connection that is used to query.
there was actually a (get-else
in the query that I did not recognize as the problem here
> it was giving me a string when there is no contract-end there This is wired. when it don't have contract/end, it should simply don't match
(require '[datomic.client.api :as d])
(let [conn (-> {:server-type :dev-local
:system "hello"}
d/client
(doto (d/delete-database {:db-name "hello"})
(d/create-database {:db-name "hello"}))
(d/connect {:db-name "hello"})
(doto (d/transact {:tx-data [{:db/ident :contract/id
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one}
{:db/ident :contract/end
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one}]})))
{:keys [db-after]} (d/transact conn
{:tx-data [{:contract/id "1"}
{:contract/id "2"
:contract/end #inst"2000"}
{:contract/id "3"
:contract/end #inst"3000"}]})]
(d/q '[:find ?e ?contract-end
:in $ ?date
:where
[?e :contract/end ?contract-end]
[(< ?date ?contract-end)]]
db-after
(java.util.Date.)))
=> [[83562883711053 #inst"3000-01-01T00:00:00.000-00:00"]]
see
(d/q '[:find ?contract-end => #{[#inst "2022-02-01T12:56:01.393-00:00"]}
:in $ ?date
:where
[?e :contract/end ?contract-end]
[(> ?date ?contract-end)]]
[[1 :contract/end (Date.)]
[2 :contract/end older]
[3 :contract/end "-"]]
(java.util.Date.)))
results in
; eval (current-form): (d/q '[:find ?contract-end :in $ ?date :where [?e :...
; (err) Execution error (ClassCastException) at (REPL:1).
; (err) null
yeah, sorry. there is a get-else
that tripped me off. it inserted a string where there should be an inst.