Filtrex v0.3.0 Filtrex
Filtrex consists of the following primary components:
Filtrex- handles the overall parsing of filters and delegates toFiltrex.ASTto build an ecto query expressionFiltrex.Condition- an abstract module built to delegate to specific condition modules in the format ofFiltrex.Condition.Typewhere the type is converted to CamelCase (SeeFiltrex.Condition.Text.parse/2)Filtrex.Params- an abstract module for parsing plug-like params from a query string into a filterFiltrex.Fragment- simple struct to hold generated expressions and values to be used when generating queries for ectoFiltrex.Type.Config- struct to hold various configuration and validation options for creating a filter
Summary
Functions
Parses a filter expression and returns errors or the parsed filter with the appropriate parsed sub-structures
Parses a filter expression, like parse/2. If any exception is raised when
parsing the map, a %Filtrex{empty: true} struct will be returned
This function converts Plug-decoded params like the example below into a filtrex struct based on options in the configs.
%{"comments_contains" => "love",
"title" => "My Blog Post",
"created_at_between" => %{"start" => "2014-01-01", "end" => "2016-01-01"}}
Converts Plug-decoded params into a Filtrex struct, like parse_params/1. If
an exception is raised while parsing the params, a %Filtrex{empty: true} struct
will be returned
Converts a filter with the specified ecto module name into a valid ecto query expression that is compiled when called
Validates the rough filter params structure
Types
Functions
Specs
parse([Filtrex.Type.Config.t], Map.t) ::
{:errors, List.t} |
{:ok, Filtrex.t}
Parses a filter expression and returns errors or the parsed filter with the appropriate parsed sub-structures.
The configs option is a list of type configs (See Filtrex.Type.Config)
Example:
[%Filtrex.Type.Config{type: :text, keys: ~w(title comments)}]
Specs
parse!([Filtrex.Type.Config.t], Map.t) :: Filtrex.t
Parses a filter expression, like parse/2. If any exception is raised when
parsing the map, a %Filtrex{empty: true} struct will be returned.
This function converts Plug-decoded params like the example below into a filtrex struct based on options in the configs.
%{"comments_contains" => "love",
"title" => "My Blog Post",
"created_at_between" => %{"start" => "2014-01-01", "end" => "2016-01-01"}}
Converts Plug-decoded params into a Filtrex struct, like parse_params/1. If
an exception is raised while parsing the params, a %Filtrex{empty: true} struct
will be returned.
Converts a filter with the specified ecto module name into a valid ecto query expression that is compiled when called.
If a %Filtrex{empty: true} struct is passed as the filter, the query will
not be modified. If you want the query to return no results when this happens,
set the allow_empty option to true:
Filtrex.query(query, filter, allow_empty: true)