This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-26
Channels
- # announcements (2)
- # babashka (55)
- # beginners (107)
- # calva (65)
- # cider (5)
- # clara (4)
- # clj-kondo (17)
- # cljs-dev (38)
- # cljsrn (16)
- # clojure (117)
- # clojure-australia (8)
- # clojure-europe (13)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-provo (2)
- # clojure-sweden (9)
- # clojure-taiwan (1)
- # clojure-uk (41)
- # clojurescript (40)
- # code-reviews (1)
- # conjure (40)
- # cursive (4)
- # datomic (11)
- # events (2)
- # fulcro (33)
- # graalvm (1)
- # jobs (2)
- # jobs-discuss (19)
- # lsp (18)
- # off-topic (58)
- # polylith (2)
- # quil (2)
- # react (28)
- # reagent (35)
- # reitit (3)
- # remote-jobs (1)
- # ring (9)
- # sci (76)
- # shadow-cljs (19)
- # sql (10)
- # testing (5)
- # vim (13)
- # xtdb (5)
Hi, i'm a bit stuck on writing a query that orders results on a field {:msg/read-on <a date>}
that might not exist in a document. How should i go about this?
For now I break up the query in two queries where one uses a not-join
, I was wondering whether i can express this in one single query using Crux datalog.
Hey @U052A8RUT 👋 we tend to go one of two routes for this one:
- if it's straightforward enough, add :msg/read-on nil
when you index the documents
- otherwise, the following pattern should help you:
;; docs
[[:crux.tx/put {:crux.db/id :foo}]
[:crux.tx/put {:crux.db/id :bar, :value 2}]]
;; query
'{:find [?e ?value]
:where [[?e :crux.db/id]
(or [?e :value ?value]
(and (not-join [?e] [?e :value])
[(identity nil) ?value]))]}
;; => #{[:bar 2] [:foo nil]}
Thank your very much! My datalog-fu is not yet black-belt, but I'm trying 😉
The other variation for this, which I personally find more readable, uses an or-join
at the top level, see https://github.com/juxt/crux/blob/5b93a04259fdc078a8de8f1777084164abb795e5/crux-test/test/crux/query_test.clj#L1778-L1781
I'm not actually certain whether one might be better/faster than the other though :thinking_face: