This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-25
Channels
- # aleph (18)
- # announcements (7)
- # asami (18)
- # babashka (15)
- # babashka-sci-dev (79)
- # beginners (61)
- # calva (4)
- # clj-kondo (23)
- # cljfx (16)
- # cljs-dev (6)
- # clojure (63)
- # clojure-bay-area (3)
- # clojure-europe (33)
- # clojure-nl (1)
- # clojure-survey (4)
- # clojure-uk (5)
- # clojurescript (136)
- # conjure (1)
- # cursive (8)
- # datahike (7)
- # datalevin (1)
- # datomic (30)
- # emacs (10)
- # events (2)
- # figwheel (2)
- # fulcro (20)
- # google-cloud (1)
- # lsp (6)
- # luminus (4)
- # malli (5)
- # music (3)
- # nextjournal (1)
- # off-topic (9)
- # other-languages (3)
- # pathom (16)
- # polylith (34)
- # re-frame (14)
- # reagent (19)
- # releases (6)
- # sci (2)
- # shadow-cljs (33)
I would like to improve this query. First: the link to :tracking/invoice has either no or one reference. Is it possible to express this in the pull syntax? Currently I get a vector of :tracking/invocie. And then I want to filter by :invoice/status. I put the contains? clause, but I think there must be a way how I give a vector of possible matches. I guess with a vector the query will be run faster?
(def xero-orders-tracking
'[:find [(pull ?id [* {:tracking/_invoice [:tracking/tag :tracking/number]}]) ...]
:in $
:where
[?id :invoice/id _]
[?id :invoice/type "ACCREC"]
[?id :invoice/status ?status]
[(contains? #{"AUTHORISED" "PAID"} ?status)]
])
Thanks!!!Additionally: Order matters.
Put the most restraining clause first.
In this case, it should be [?id :invoice/type "ACCREC"]
Thanks @U4VT24ZM3 So I guess this is how the order of my where clauses should be then:
[?id :invoice/type "ACCREC"]
[?id :invoice/status ?status]
[(contains? #{"AUTHORISED" "PAID"} ?status)]
[?id :invoice/id _]
back-references like :tracking/_invoice
can't help but be "many", even if your data happens to have only one, since there's no way to control how many incoming refs there might be.
you'll have to post-process that with (update _ :tracking/invoice first)
or similar.
you can probably skip the [?id :invoice/id _]
at the start, unless there are entities with :invoice/type
and :invoice/status
that don't have :invoice/id
.
you can express the status constraint as (or [?id :invoice/status "AUTHORIZED"] [?id :invoice/status "PAID"])