Alembic v2.1.0 Alembic.Pagination.Page

A page using paged pagination where the size of pages is fixed.

Summary

Types

t()
  • number - the 1-based page number
  • size - the size of this page and all pages

Functions

Extracts number from query "page[number]" and and size from query "page[size]"

Extracts number from uri query "page[number]" and size from uri query "page[size]"

Converts the page back to params

Types

t :: %Alembic.Pagination.Page{number: non_neg_integer, size: pos_integer}
  • number - the 1-based page number
  • size - the size of this page and all pages

Functions

from_query(query)

Specs

from_query(String.t) :: t

Extracts number from query "page[number]" and and size from query "page[size]".

iex> Alembic.Pagination.Page.from_query("page%5Bnumber%5D=2&page%5Bsize%5D=10")
%Alembic.Pagination.Page{number: 2, size: 10}

If query does not have both "page[number]" and "page[size]" then nil is returned

iex> Alembic.Pagination.Page.from_query("page%5Bnumber%5D=2")
nil
iex> Alembic.Pagination.Page.from_query("page%5Bsize%5D=10")
nil
iex> Alembic.Pagination.Page.from_query("")
nil
from_uri(uri)

Specs

from_uri(URI.t) :: t | nil

Extracts number from uri query "page[number]" and size from uri query "page[size]".

iex> Alembic.Pagination.Page.from_uri(%URI{query: "page%5Bnumber%5D=2&page%5Bsize%5D=10"})
%Alembic.Pagination.Page{number: 2, size: 10}

If a URI.t query does not have both "page[number]" and "page[size]" then nil is returned

iex> Alembic.Pagination.Page.from_uri(%URI{query: "page%5Bnumber%5D=2"})
nil
iex> Alembic.Pagination.Page.from_uri(%URI{query: "page%5Bsize%5D=10"})
nil
iex> Alembic.Pagination.Page.from_uri(%URI{query: ""})
nil

If a URI.t does not have a query then nil is returned

iex> Alembic.Pagination.Page.from_uri(%URI{query: nil})
nil
to_params(page)

Specs

to_params(t) :: map

Converts the page back to params.

iex> Alembic.Pagination.Page.to_params(%Alembic.Pagination.Page{number: 2, size: 10})
%{
  "page" => %{
    "number" => 2,
    "size" => 10
  }
}