View Source Flop.Filter (Flop v0.18.4)
Defines a filter.
Link to this section Summary
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.
Operator | Value | WHERE clause |
---|---|---|
:== | "Salicaceae" | WHERE column = 'Salicaceae' |
:!= | "Salicaceae" | WHERE column != 'Salicaceae' |
:=~ | "cyth" | WHERE column ILIKE '%cyth%' |
:empty | true | WHERE (column IS NULL) = true |
:empty | false | WHERE (column IS NULL) = false |
:not_empty | true | WHERE (column IS NOT NULL) = true |
:not_empty | false | WHERE (column IS NOT NULL) = false |
:<= | 10 | WHERE column <= 10 |
:< | 10 | WHERE column < 10 |
:>= | 10 | WHERE column >= 10 |
:> | 10 | WHERE 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_and | "Rubi Rosa" | WHERE column LIKE '%Rubi%' AND column LIKE '%Rosa%' |
:like_or | ["Rubi", "Rosa"] | WHERE column LIKE '%Rubi%' OR 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_and | "Rubi Rosa" | WHERE column ILIKE '%Rubi%' AND column ILIKE '%Rosa%' |
:ilike_or | ["Rubi", "Rosa"] | WHERE column ILIKE '%Rubi%' OR column ILIKE '%Rosa%' |
:ilike_or | "Rubi Rosa" | WHERE column ILIKE '%Rubi%' OR column ILIKE '%Rosa%' |
The filter operators :ilike_and
, :ilike_or
, :like_and
and :like_or
accept both strings and list of strings.
- If the filter value is a string, it will be split at whitespace characters
and the segments are combined with
and
oror
. - If a list of strings is passed, the individual strings are not split, and
the list items are combined with
and
oror
.
Represents filter query parameters.
fields
Fields
field
: The field the filter is applied to. The allowed fields can be restricted by derivingFlop.Schema
in your Ecto schema.op
: The filter operator.value
: The comparison value of the filter.
Link to this section Functions
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]
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]