This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-13
Channels
- # announcements (6)
- # babashka (96)
- # beginners (159)
- # calva (16)
- # cider (17)
- # clj-kondo (4)
- # cljdoc (6)
- # cljfx (3)
- # clojure (202)
- # clojure-europe (21)
- # clojure-italy (2)
- # clojure-nl (36)
- # clojure-spec (6)
- # clojure-uk (16)
- # clojurescript (29)
- # conjure (25)
- # cursive (29)
- # data-science (12)
- # datalog (18)
- # datomic (58)
- # depstar (73)
- # duct (16)
- # emacs (65)
- # events (3)
- # fulcro (8)
- # honeysql (12)
- # jackdaw (6)
- # jobs (7)
- # jobs-discuss (3)
- # kaocha (50)
- # leiningen (8)
- # lsp (14)
- # malli (83)
- # meander (34)
- # off-topic (2)
- # polylith (4)
- # proletarian (7)
- # re-frame (8)
- # releases (9)
- # remote-jobs (3)
- # shadow-cljs (101)
- # sql (1)
- # tools-deps (48)
- # vim (7)
- # xtdb (13)
- # yada (14)
I am wondering how can I perform casting during a query? I have fields in crux that are datetime, but I want to get them back as date
so, you essentially want to do something like (.toDate ?my-datetime)
just before returning the results?
you can't use Clojure's Java interop like that directly within a query, but you can wrap the call in a Clojure function that can be used as a custom predicate
like
(defn datetime->date [dt]
(.toDate dt))
(crux/q db '{:find [d]
:where [[:my-e :date my-date]
[(my.ns/datetime->date my-date) d]]}
thanks @U899JBRPF I will test this. My idea is that I am using aggregation and want to aggregate by date not datetime
I noticed the need to specify the namespace, so do you have more docs on custom predicates?
No additional docs at the moment...but that's pretty much all there is to it. You can also destructure the output like :in