filterable v0.0.2 Filterable

Filterable allows to map incoming controller parameters to filter functions:

defmodule Filterable do
  def title(_conn, query, value) do
    query |> where(title: ^value)
  end
end

Then we can apply defined query params filters inside controller action:

def index(conn, params) do
  posts = Post |> apply_filters(conn) |> Repo.all
  render(conn, "index.html", posts: posts)
end

By default apply_filters uses filter functions defined in AppName.ControllerModule.Filterable module. Other module can be set explicitly with filterable macro:

filterable UserFilters, param: "filter"

Summary

Macros

Allows to select module with defined filter functions with options

Macros

filterable(module, options \\ [])

Allows to select module with defined filter functions with options.

Options

  • :param - Sets top level query param for filters.