Filter

Any valid Walkable S-expression that evaluates to boolean (not just some truthy values in Clojure sense) can be used in a filter.

One-off filter

Filter can be specified in a query’s parameters.

`[{(:people/list {:filter [:or [:like :person/name "jon%"]
                               [:< :person/yob 1970]]})
   [:person/name :person/yob]]}

Permanent filters

You may want to enforce filters for specific roots/idents/joins:

  • for DRY reason: you don’t want to retype the same filter again and again.

  • for security reason: once you define some constraints to limit what the clients can access for an ident or join, they’re free to play with whatever left open to them.

;; registry
[{:key :people/list
  :type :root
  :table "..."
  :filter [:= :person/hidden false]}
 {:key :person/friends
  :type :join
  :join-path [...]
  :filter [:or
           [:like :person/name "jon%"]
           [:like :person/name "mary%"]]}]

Joins in filters

You’ve seen filters used against columns of the current table. If you have defined some :joins in your registry, you can also impose constraints on columns of the joined tables, too.

;; find all people whose name starts with "jon" or whose friend's name
;; starts with "jon".
`[{(:people/list {:filter [:or [:like :person/name "jon%"]
                              {:person/friend [:like :person/name "jon%"]}]})
[:person/name :person/yob]}]

You can have many such joins in filters and combine them with other expressions using :and/:or/:not however you like.