OuterfacesEctoApi.QueryEngine.QueryPager (Outerfaces Ecto API v0.2.9)

View Source

Limit and offset from the request's query param, and the page_info that describes them. paging/2 works out the limit and offset once, so the rows returned and the page_info reported always agree.

Summary

Functions

Applies a paging/2 result to query.

Applies limit and offset to a given query.

The page_info for a paging/2 result and the total row count.

The limit and offset to apply. Integers or integer strings are accepted.

Types

pagination_info()

@type pagination_info() :: %{
  total_count: non_neg_integer(),
  total_pages: pos_integer(),
  has_next_page: boolean(),
  has_previous_page: boolean(),
  limit: non_neg_integer(),
  offset: non_neg_integer()
}

paging()

@type paging() :: %{limit: non_neg_integer() | nil, offset: non_neg_integer()}

Functions

apply(query, map)

@spec apply(Ecto.Query.t(), paging()) :: Ecto.Query.t()

Applies a paging/2 result to query.

apply_paging(query, params)

@spec apply_paging(Ecto.Query.t(), map()) :: Ecto.Query.t()

Applies limit and offset to a given query.

QueryPager.apply_paging(query, %{"query" => ~s({"limit": 10, "offset": 20})})

compute_pagination(params, total_count)

@spec compute_pagination(map(), non_neg_integer()) :: pagination_info()

page_info(map, total_count)

@spec page_info(paging(), non_neg_integer()) :: pagination_info()

The page_info for a paging/2 result and the total row count.

paging(params, opts \\ [])

@spec paging(map(), Keyword.t()) :: {:ok, paging()} | {:error, :invalid_query}

The limit and offset to apply. Integers or integer strings are accepted.

Options: :default_limit (when none is sent) and :max_limit (the largest allowed). Without either, a request that sends no limit gets every row.