stein v0.5.2 Stein.Filter behaviour View Source

Filter an Ecto.Query by a map of parameters.

Example Module

defmodule MyApp.Orders do
  @behaviour Stein.Filter

  def filter_on_attribute({"name", value}, query) do
    value = "%" <> value <> "%"
    where(query, [o], like(o.name, ^value))
  end

  def filter_on_attribute(_, query), do: query
end

Link to this section Summary

Functions

Filter a query based on a set of params

Callbacks

This will be reduced from the query params that are passed into filter/3

Link to this section Types

Link to this type

attribute() View Source
attribute() :: String.t()

Link to this type

callback_module() View Source
callback_module() :: atom()

Link to this type

params() View Source
params() :: %{required(attribute()) => value()}

Link to this section Functions

Link to this function

filter(query, filter, module) View Source
filter(query(), params(), callback_module()) :: query()

Filter a query based on a set of params

This will reduce the query over the filter parameters.

Link to this section Callbacks

Link to this callback

filter_on_attribute(pair, query) View Source
filter_on_attribute(pair(), query()) :: query()

This will be reduced from the query params that are passed into filter/3