This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-25
Channels
- # anglican (2)
- # babashka (53)
- # beginners (99)
- # brompton (1)
- # calva (28)
- # circleci (43)
- # clj-commons (4)
- # clj-kondo (176)
- # cljsrn (22)
- # clojars (7)
- # clojure (175)
- # clojure-australia (2)
- # clojure-europe (20)
- # clojure-germany (1)
- # clojure-uk (5)
- # clojurescript (195)
- # cursive (18)
- # datomic (13)
- # emacs (2)
- # farolero (9)
- # find-my-lib (6)
- # fulcro (8)
- # graalvm (12)
- # gratitude (5)
- # helix (11)
- # improve-getting-started (36)
- # introduce-yourself (3)
- # jackdaw (21)
- # jobs (2)
- # joker (2)
- # malli (65)
- # meander (24)
- # nbb (2)
- # off-topic (4)
- # pathom (2)
- # polylith (17)
- # portal (5)
- # react (3)
- # reagent (22)
- # releases (1)
- # ring (4)
- # shadow-cljs (79)
- # show-and-tell (2)
- # testing (5)
- # tools-deps (9)
- # xtdb (12)
Regarding rules in Crux: the examples all show rules defined inline in the query. How can I pass a rule to a query in Crux, defined externally from the query?
Yep, that's the right answer. Crux doesn't support parametrisation of rules via :in (since they must be known ahead of time, for query compilation)
Perfect, I just don't want to copy and paste the same 30 line rule into every query.
I have this test snippet:
(let [node db.mounts/crux-node
e1 {:crux.db/id {:e/id 1}
:e/id 1
:e/d-id {:d/id 99}}
;; get d1 but also show that e1 points at it
d1 {:crux.db/id {:d/id 99}
:d/id 99}]
(crux/await-tx node
(crux/submit-tx node [[:crux.tx/put e1]]))
(crux/await-tx node
(crux/submit-tx node [[:crux.tx/put d1]]))
(prn
(crux/q (crux/db node)
'{:find [(pull d [:d/id
{(:e/_d-id {:as :e/id :cardinality :one}) [:e/id]}])]
:where [[d :d/id 99]]})))
It prints:
#{[{:d/id 99, :e/id #:e{:id 1}}]}
I would like for it to print:
#{[{:d/id 99, :e/id 1}]}
Is it possible without using Clojure to reshape the result?for the example above, you might be better off using a vanilla query without pull
, given you have a flat result - instead opting for :keys
:
(crux/q (crux/db node)
'{:find [d-id e-id]
:in [d-id]
:keys [d/id e/id]
:where [[d :d/id d-id]
[e :e/d-id d]
[e :e/id e-id]]}
99)
;; => #{{:d/id 99, :e/id 1}}
Is there a way to provide a default value using vanilla queries the same way that's possible with pull
? I have an entity with an optional field and I'd like to query for all those documents regardless of whether the optional field is present or not.
Is it the ID relationship that's optional? if not, you could consider adding more pull
clauses to the :find
to achieve something similar