Filtrex v0.2.0 Filtrex

Filtrex consists of the following primary components:

  • Filtrex - handles the overall parsing of filters and delegates to Filtrex.AST to build an ecto query expression

  • Filtrex.Condition - an abstract module built to delegate to specific condition modules in the format of Filtrex.Condition.Type where the type is converted to CamelCase (See Filtrex.Condition.Text.parse/2)

  • Filtrex.Params - an abstract module for parsing plug-like params from a query string into a filter

  • Filtrex.Fragment - simple struct to hold generated expressions and values to be used when generating queries for ecto

  • Filtrex.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

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"}}

Macros

Converts a filter with the specified ecto module name into a valid ecto query expression that is compiled when called

Types

Functions

parse(configs, arg2)

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)}]
parse_params(configs, params)

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"}}

Macros

query(filter, model)

Specs

query(term, Filter.t, module) :: Ecto.Query.t

Converts a filter with the specified ecto module name into a valid ecto query expression that is compiled when called.