View Source RecordList.Pagination (record_list v0.1.3)

A module that builds a RecordList.Pagination.t() struct with information about the paging of the records.

Link to this section Summary

Types

The total number of records returned by the query - typically from doing a count prior to paging.

The current page.

The number of records per page.

t()

A struct to capture paging information for use with, for example, paging controls.

Functions

Calculates the tota; number of pages.

Builds a %RecordList.Pagination{} struct from the current_page, per_page and count arguments.

Calculates the offset.

Adds the records_from value. 0 if count is nil, or 0. 1 if the previous_page is nil and otherwise 1 + offset.

Adds the next page unless current page is the last page.

Adds the previous page unless current page is the first page.

Adds the records_to value. 0 if count is nil, or 0. count if count < per_page. records_count if is_nil(next_page). Otherwise current_page * per_page.

The per_page and current_page values can potentially be passed in as strings, e.g. "20" or "2". We ensure that the values are converted to integers in order to do the required calculations.

Link to this section Types

@type count() :: integer()

The total number of records returned by the query - typically from doing a count prior to paging.

@type current_page() :: nil | binary() | integer()

The current page.

@type per_page() :: nil | binary() | integer()

The number of records per page.

@type t() :: %RecordList.Pagination{
  current_page: term(),
  next_page: term(),
  per_page: term(),
  previous_page: term(),
  records_count: term(),
  records_from: term(),
  records_offset: term(),
  records_to: term(),
  total_pages: term()
}

A struct to capture paging information for use with, for example, paging controls.

attributes

Attributes

  • :per_page- the number of records to return per page.
  • :records_count- The number of records in the query, prior to applying pagination. The result set to be paged through.
  • :records_from- The :id or :index of the first record in the paged result set.
  • :records_to- The :id or :index of the last record in the paged result set.
  • :records_offset- The offset from the start of the result set. This is 1 less than :records_from.
  • :total_pages- The number of pages, given per_page to get through the total results.
  • :next_page- the next page number.
  • :previous_page- the previous page number.
  • :current_page- the current page number.

Link to this section Functions

Link to this function

add_total_pages(pagination)

View Source

Calculates the tota; number of pages.

Link to this function

build(current_page, per_page, count)

View Source
@spec build(current_page(), per_page(), count()) :: t()

Builds a %RecordList.Pagination{} struct from the current_page, per_page and count arguments.

Link to this function

calculate_offset(pagination)

View Source

Calculates the offset.

Link to this function

maybe_add_from(pagination)

View Source

Adds the records_from value. 0 if count is nil, or 0. 1 if the previous_page is nil and otherwise 1 + offset.

Link to this function

maybe_add_next_page(pagination)

View Source

Adds the next page unless current page is the last page.

Link to this function

maybe_add_previous_page(pagination)

View Source

Adds the previous page unless current page is the first page.

Link to this function

maybe_add_to(pagination)

View Source

Adds the records_to value. 0 if count is nil, or 0. count if count < per_page. records_count if is_nil(next_page). Otherwise current_page * per_page.

The per_page and current_page values can potentially be passed in as strings, e.g. "20" or "2". We ensure that the values are converted to integers in order to do the required calculations.