View Source Flop.Filter (Flop v0.17.1)

Defines a filter.

Link to this section Summary

Types

Represents valid filter operators.

t()

Represents filter query parameters.

Functions

Returns the allowed operators for the given Ecto type.

Returns the allowed operators for the given schema module and field.

Link to this section Types

@type op() ::
  :==
  | :!=
  | :=~
  | :empty
  | :not_empty
  | :<=
  | :<
  | :>=
  | :>
  | :in
  | :not_in
  | :contains
  | :not_contains
  | :like
  | :like_and
  | :like_or
  | :ilike
  | :ilike_and
  | :ilike_or

Represents valid filter operators.

OperatorValueWHERE clause
:=="Salicaceae"WHERE column = 'Salicaceae'
:!="Salicaceae"WHERE column != 'Salicaceae'
:=~"cyth"WHERE column ILIKE '%cyth%'
:emptytrueWHERE (column IS NULL) = true
:emptyfalseWHERE (column IS NULL) = false
:not_emptytrueWHERE (column IS NOT NULL) = true
:not_emptyfalseWHERE (column IS NOT NULL) = false
:<=10WHERE column <= 10
:<10WHERE column < 10
:>=10WHERE column >= 10
:>10WHERE column > 10
:in["pear", "plum"]WHERE column = ANY('pear', 'plum')
:not_in["pear", "plum"]WHERE column = NOT IN('pear', 'plum')
:contains"pear"WHERE 'pear' = ANY(column)
:not_contains"pear"WHERE 'pear' = NOT IN(column)
:like"cyth"WHERE column LIKE '%cyth%'
:like_and"Rubi Rosa"WHERE column LIKE '%Rubi%' AND column LIKE '%Rosa%'
:like_or"Rubi Rosa"WHERE column LIKE '%Rubi%' OR column LIKE '%Rosa%'
:ilike"cyth"WHERE column ILIKE '%cyth%'
:ilike_and"Rubi Rosa"WHERE column ILIKE '%Rubi%' AND column ILIKE '%Rosa%'
:ilike_or"Rubi Rosa"WHERE column ILIKE '%Rubi%' OR column ILIKE '%Rosa%'
@type t() :: %Flop.Filter{field: atom() | String.t(), op: op(), value: any()}

Represents filter query parameters.

fields

Fields

  • field: The field the filter is applied to. The allowed fields can be restricted by deriving Flop.Schema in your Ecto schema.
  • op: The filter operator.
  • value: The comparison value of the filter.

Link to this section Functions

@spec allowed_operators(atom()) :: [op()]

Returns the allowed operators for the given Ecto type.

If the given value is not a native Ecto type, a list with all operators is returned.

iex> allowed_operators(:integer)
[:==, :!=, :empty, :not_empty, :<=, :<, :>=, :>, :in, :not_in]
Link to this function

allowed_operators(module, field)

View Source
@spec allowed_operators(atom(), atom()) :: [op()]

Returns the allowed operators for the given schema module and field.

If the given value is not a native Ecto type, a list with all operators is returned.

iex> allowed_operators(Pet, :age)
[:==, :!=, :empty, :not_empty, :<=, :<, :>=, :>, :in, :not_in]