Fork me on GitHub

I'm playing around with a todo example app and I'm trying to add filtering. Here's my query: `


`[:find [?tid ...]
            [?tid :app/type :type/task]
            [?tid :task/done? ?status]
            [(= ?status (case filter
                            :filter/complete true
                            :filter/incomplete false

Oliver George02:10:28

[:find [?tid ...]
 :in $ ?status
   [?tid :app/type :type/task]
   [?tid :task/done? ?status]]

Oliver George02:10:10

That approach is: pass the boolean as a param

Oliver George02:10:59

(let [status (case filter :filter/complete true :filter/incomplete false true))] (d/q query db status))

Oliver George02:10:36

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?

Oliver George02:10:27

I know there's some tips documented but can't find them right now

Oliver George02:10:43

I saw someone say they just pass the predicate in as a param

Oliver George02:10:56

Not sure that's the best way - others might comment

Oliver George02:10:28

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

Oliver George02:10:20

It's been a little while for me so I'm not the best to give advice


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?