LiveFilter.Params.Parser (LiveFilter v0.3.0)

Copy Markdown View Source

Converts PostgREST URL query params into a list of Filter structs, matched against a provided filter config list.

Operator values are parsed with PgRest.Grammar.Filter.parse_condition/2 and mapped to LiveFilter operators: is.null/is.not_null become :is_null, not.in becomes :not_in, not.eq/not.neq become :neq/:eq, and cs/cd/ov values are split into lists. Other negations and any/all modifiers have no LiveFilter operator, so the raw value falls back to the config's default operator, as does a value without an operator prefix (?search=hello). A value with an operator prefix that the grammar rejects (is.maybe, in.abc) is skipped; from_params_with_errors/2 reports it.

Summary

Types

A param that could not be parsed, as a filter with its raw value, with the reason.

Functions

Parses URL params into {filters, remaining_params}.

Like from_params/2, and also returns the skipped params: a value with an operator prefix that PgRest.Grammar.Filter.parse_condition/2 rejects, as a filter holding the raw value with the grammar's PGRST100.

Types

rejection()

@type rejection() :: {LiveFilter.Filter.t(), PgRest.Error.t()}

A param that could not be parsed, as a filter with its raw value, with the reason.

Functions

from_params(params, configs)

@spec from_params(map(), [LiveFilter.FilterConfig.t()]) ::
  {[LiveFilter.Filter.t()], map()}

Parses URL params into {filters, remaining_params}.

Matches each param against the config list by field name or custom_param. Merges paired gte/lte params into a single date_range filter. Unrecognized params are returned as remaining.

from_params_with_errors(params, configs)

@spec from_params_with_errors(map(), [LiveFilter.FilterConfig.t()]) ::
  {[LiveFilter.Filter.t()], map(), [rejection()]}

Like from_params/2, and also returns the skipped params: a value with an operator prefix that PgRest.Grammar.Filter.parse_condition/2 rejects, as a filter holding the raw value with the grammar's PGRST100.