Torch v2.0.0-rc.2 Torch.Helpers View Source
Provides helper functions for Torch-generated controllers.
Link to this section Summary
Functions
Paginates a given Ecto.Queryable
using Scrivener
Determines how the query for an index action should be sorted
Link to this section Types
Link to this type
params()
View Source
params()
View Source
params() :: map()
params() :: map()
Link to this section Functions
Link to this function
paginate(query, repo, params, settings \\ [page_size: 10])
View Source
paginate(query, repo, params, settings \\ [page_size: 10])
View Source
paginate(Ecto.Queryable.t(), Ecto.Repo.t(), params(), Keyword.t()) ::
%Scrivener.Page{
entries: term(),
page_number: term(),
page_size: term(),
total_entries: term(),
total_pages: term()
}
paginate(Ecto.Queryable.t(), Ecto.Repo.t(), params(), Keyword.t()) :: %Scrivener.Page{ entries: term(), page_number: term(), page_size: term(), total_entries: term(), total_pages: term() }
Paginates a given Ecto.Queryable
using Scrivener.
This is a very thin wrapper around Scrivener.paginate/2
, so see the Scrivener
Ecto documentation for more details.
Parameters
query
: AnEcto.Queryable
to paginate.repo
: Your Repo module.params
: Parameters from yourconn
. For example%{"page" => 1}
.settings
: A list of settings for Scrivener, including:page_size
.
Examples
paginate(query, Repo, params, [page_size: 15])
# => %Scrivener.Page{...}
Link to this function
sort(params) View Source
Determines how the query for an index action should be sorted.
Relies on the "sort_field"
and "sort_direction"
parameters to be passed.
By default, it sorts by :id
in ascending order.
Examples
iex> sort(%{"sort_field" => "name", "sort_direction" => "desc"})
{:desc, :name}
iex> sort(%{})
{:asc, :id}
In a query pipeline, use in conjunction with Ecto.Query.order_by/3
:
order_by(query, ^sort(params))