ecto_searcher v0.2.0 EctoSearcher.Sorter View Source
Module for sorting
Usage
sortable_fields = [:name, :description]
sorted_query = EctoSearcher.Sorter.sort(SomeEctoModel, %{"field" => "name", "order" => "desc"}, sortable_fields)
MySuperApp.Repo.all(sorted_query)
Link to this section Summary
Link to this section Functions
Link to this function
sort(base_query, schema, sort_query) View Source
Shortcut for sort/5
Link to this function
sort(base_query, schema, sort_query, mapping, sortable_fields \\ nil) View Source
Builds sort query
Takes %Ecto.Query{}
as base_query
and ecto model as schema
.
sort_params
should be a map with "field" and "order" like this:
%{
"field" => "name",
"order" => "asc"
}
mapping
should implement EctoSearcher.Mapping
behavior. EctoSearcher.Mapping.Default
provides some basics.
sortable_fields
is a list with fields (atoms) permitted for sorting. If not provided (or nil
) all fields are allowed for sorting:
[:name, :description]