View Source QueryElf.Plugins.AutomaticSorters (query_elf v0.4.1)
Plugin for automatically defining sorters for a set of fields.
It accepts the following options:
:fields
- the list of fields for which to define sorters. (required)
Example
This definition:
defmodule MyQueryBuilder do
use QueryElf,
schema: MySchema,
plugins: [
{QueryElf.Plugins.AutomaticSorters, fields: ~w[inserted_at]a}
]
end
is equivalent to:
defmodule MyQueryBuilder do
use QueryElf,
schema: MySchema
def sort(:inserted_at, direction, _args, query) do
case direction do
:asc -> order_by(query, asc: :inserted_at)
:desc -> order_by(query, desc: :inserted_at)
end
end
end