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))]]
This blows up with Error: Unknown predicate 'cljs.core/=
The datascript readme says that it supports "Predicates and user functions in query", so I'm surprised to see this blow up. Am I getting the syntax wrong?
[: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.e. display all tasks)
Or should I just apply the filter to the results after fetching all tasks?
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