View Source QueryElf.Plugins.AutomaticFilters (query_elf v0.4.1)
Plugin for automatically defining filters for a set of fields.
It accepts the following options:
:fields- the list of fields for which to define filters. (required)
The defined filters will vary according to the field type in the schema:
idorbinary_id::$FIELD- checks if the field is equal to the given value:$FIELD__neq- checks if the field is different from the given value:$FIELD__in- checks if the field is contained in the given enumerable:$FIELD__not_in- checks if the field is not contained in the given enumerable
boolean::$FIELD- checks if the field is equal to the given value
integer,floatordecimal::$FIELD- checks if the field is equal to the given value:$FIELD__neq- checks if the field is different from the given value:$FIELD__in- checks if the field is contained in the given enumerable:$FIELD__not_in- checks if the field is not contained in the given enumerable:$FIELD__gt- checks if the field is greater than the given value:$FIELD__lt- checks if the field is lower than the given value:$FIELD__gte- checks if the field is greater than or equal to the given value:$FIELD__lte- checks if the field is lower than or equal to the given value:$FIELD__is_empty- checks if the field's value is nil
string::$FIELD- checks if the field is equal to the given value:$FIELD__neq- checks if the field is different from the given value:$FIELD__in- checks if the field is contained in the given enumerable:$FIELD__not_in- checks if the field is not contained in the given enumerable:$FIELD__contains- checks if the field contains the given string:$FIELD__starts_with- checks if the field starts with the given string:$FIELD__ends_with- checks if the field ends with the given string
{:array, inner_type}::$FIELD- checks if the field is equal to the given value:$FIELD__neq- checks if the field is different from the given value:$FIELD__includes- checks if the field includes the given value:$FIELD__does_not_include- checks if the field does not include the given value:$FIELD__is_empty- checks if the field's value is nil
date,time,naive_datetime,datetime,time_usec,naive_datetime_usecordatetime_usec::$FIELD- checks if the field is equal to the given value:$FIELD__neq- checks if the field is different from the given value:$FIELD__in- checks if the field is contained in the given enumerable:$FIELD__not_in- checks if the field is not contained in the given enumerable:$FIELD__after- checks if the field occurs after the given value:$FIELD__before- checks if the field occurs before the given value:$FIELD__is_empty- checks if the field's value is nil
Any other types are simply ignored.
Example
defmodule MyQueryBuilder do
use QueryElf,
schema: MySchema,
plugins: [
{QueryElf.Plugins.AutomaticFilters, fields: ~w[id name age is_active]a}
]
end
MyQueryBuilder.build_query(id__in: [1, 2, 3], name__starts_with: "John")