servant-util-beam-pg-0.1.0.2: Implementation of servant-util primitives for beam-postgres.
Safe HaskellNone
LanguageHaskell2010

Servant.Util.Beam.Postgres.Filtering

Contents

Description

Implements filtering with beam-postgres.

When setting filtering for an endpoint, you usually need to construct a filtering spec application first, which describes how to perform filtering over your rows:

filteringSpecApp
    :: FilteringSpecApp
        (QExprFilterBackend syntax s)
        [ "course" ?: 'AutoFilter Course
        , "desc" ?: 'AutoFilter Text
        , "isAwesome" ?: 'ManualFilter Bool
        ]
filteringSpecApp =
    filterOn_ "course" courseField .*.
    filterOn_ "desc" descField .*.
    customFilter_ @"isAwesome"
        (isAwesome -> (courseAwesomeness >. val_ 42) ==. val_ isAwesome) .*.
    HNil

Annotating filterOn and customFilter calls with parameter name is fully optional and used only to visually disambiguate filters of the same types.

Next, you use matches_ or filterGuard_ to build a filtering expression understandable by Beam.

Synopsis

Documentation

matches_ :: (BeamSqlBackend be, backend ~ QExprFilterBackend be s, BackendApplySomeFilter backend params) => FilteringSpec params -> FilteringSpecApp backend params -> QExpr be s Bool Source #

Applies a whole filtering specification to a set of response fields. Resulting value can be put to guard_ or filter_ function.

filtersGuard_ :: (backend ~ QFilterBackend be db s, BackendApplySomeFilter backend params) => FilteringSpec params -> FilteringSpecApp backend params -> Q be db s () Source #

Applies a whole filtering specification to a set of response fields. Resulting value can be monadically binded with the remaining query (just like guard_).

filterOn :: forall k (name :: Symbol) (backend :: k) a. Typeable a => AutoFilteredValue backend a -> FilteringApp backend ('TyNamedParam name ('AutoFilter a)) #

Implement an automatic filter. User-provided filtering operation will do filter on this value.

manualFilter :: forall k (name :: Symbol) (backend :: k) a. Typeable a => (a -> MatchPredicate backend) -> FilteringApp backend ('TyNamedParam name ('ManualFilter a)) #

Implement a manual filter. You are provided with a value which user supplied and so you have to construct a Beam predicate involving that value and relevant response fields.

Internals