This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-12
Channels
- # aleph (8)
- # announcements (9)
- # babashka (15)
- # beginners (91)
- # calva (54)
- # chlorine-clover (3)
- # cider (25)
- # clj-kondo (9)
- # cljfx (4)
- # cljsrn (12)
- # clojure (40)
- # clojure-australia (2)
- # clojure-europe (77)
- # clojure-nl (10)
- # clojure-spec (22)
- # clojure-uk (9)
- # clojurescript (39)
- # conjure (12)
- # cursive (8)
- # datascript (17)
- # datomic (22)
- # emacs (2)
- # expound (6)
- # fulcro (25)
- # kaocha (7)
- # malli (9)
- # meander (5)
- # off-topic (13)
- # pathom (8)
- # pedestal (5)
- # portal (1)
- # rdf (58)
- # re-frame (65)
- # reagent (15)
- # sci (3)
- # shadow-cljs (50)
- # test-check (6)
- # testing (3)
- # tools-deps (1)
- # vim (7)
- # xtdb (10)
I'm playing around with a todo example app and I'm trying to add filtering. Here's my query:
`
`[:find [?tid ...]
:where
[?tid :app/type :type/task]
[?tid :task/done? ?status]
[(= ?status (case filter
:filter/complete true
:filter/incomplete false
true))]]
[:find [?tid ...]
:in $ ?status
:where
[?tid :app/type :type/task]
[?tid :task/done? ?status]]
That approach is: pass the boolean as a param
(let [status (case filter :filter/complete true :filter/incomplete false true))] (d/q query db status))
As the the error... accessing cljs.core fns from queries in datomic requires some fiddling.
thanks, that's helpful and it works. If I want to take it further, and apply an optional filter, how would I go about that - where I want ?status to match true or false
I know there's some tips documented but can't find them right now
I saw someone say they just pass the predicate in as a param
Not sure that's the best way - others might comment
It's all "in memory" so no shame in filtering the results except that you might find it less expressive since you need to specify what data is returned to work with
ah, in this case I wanted to do the filtering in the query so I could just return the ids, so I take your point
It's been a little while for me so I'm not the best to give advice