query v0.3.0 Query.Builder.Sort
Provides sort details for our Query.Builder.
Link to this section Summary
Functions
Provides sorting details based on the provided params and options
Link to this section Functions
Link to this function
new(params \\ %{}, options \\ [])
new(Query.Builder.param(), list()) :: [{atom(), atom()}]
Provides sorting details based on the provided params and options.
Parameters
- params: A param map - most likely from a controller.
- options: A list of options.
Options
:default_sort
- the default sort attribute if none is provided. Defaults to “id”.:default_dir
- the default direction. Defaults to “asc”.:sort_param
- the param key to use for the sort. Deafults to “sort_by”.:dir_param
- the param key to use for the direction. Defaults to “direction”.:permitted
- a list of permitted attributes that we can sort on.
Examples
iex> Query.Builder.Sort.new(%{"sort_by" => "title", "direction" => "desc"}, %{permitted: ["title"]})
[{:desc, :title}]