View Source EctoJuno.Query.SortingTemplate behaviour (ecto_juno v0.3.0)
Behaviour for sorting by implementing which you can specify sorting parameters based on provided sort_by field
Define your sorting module with prepare_sorting_params/1 callback:
defmodule Sample.UserSorting do
use EctoJuno.Query.SortingTemplate
def prepare_sorting_params("post_" <> field) do
{Post, field, :posts}
end
def prepare_sorting_params(nil) do
{User, "inserted_at"}
end
def prepare_sorting_params(field) do
{User, field}
end
end
Link to this section Summary
Callbacks
Traverses sort_by into sorting parameters for EctoJuno.Query.Sorting.sort_query/3 or EctoJuno.Query.Sorting.sort_query/4
Link to this section Types
@type ecto_query_binding() :: atom()
@type ecto_schema() :: atom()
@type ecto_schema_or_allowed_fields() :: ecto_schema() | allowed_fields()
@type sort_field() :: String.t()
Link to this section Callbacks
@callback prepare_sorting_params(String.t() | nil) :: {ecto_schema_or_allowed_fields(), sort_field()} | {ecto_schema_or_allowed_fields(), sort_field(), ecto_query_binding()}
Traverses sort_by into sorting parameters for EctoJuno.Query.Sorting.sort_query/3 or EctoJuno.Query.Sorting.sort_query/4