View Source Indexed.Actions.Paginate (Indexed v0.3.0)

Tools for paginating in-memory data structures.

The API is meant to match Paginator as much as possible so that callers can use simple logic to decide where to pull the data from, unbeknownst to the client.

Call paginate/3 to paginate through results using opaque cursors.

Link to this section Summary

Functions

Given the relevant, presorted list of ids and a function to fetch a record by its id, build the Paginator.Page.t/0 result.

Fetches all the results matching the query within the cursors.

Link to this section Functions

Link to this function

paginate(ordered_ids, record_getter, opts \\ [])

View Source
@spec paginate(
  [id()],
  (... -> any()),
  keyword()
) :: Paginator.Page.t()

Given the relevant, presorted list of ids and a function to fetch a record by its id, build the Paginator.Page.t/0 result.

Link to this function

run(index, entity_name, params)

View Source
@spec run(Indexed.t(), atom(), keyword()) :: Paginator.Page.t() | nil

Fetches all the results matching the query within the cursors.

options

Options

  • :after - Fetch the records after this cursor.
  • :before - Fetch the records before this cursor.
  • :order_by - {direction, field_name} tuple where :direction is either :asc or :desc (default :asc). :order_field is a field name atom (eg. :updated_by). Also allowed is the field name atom alone, in which case :asc sort direction will be used.
  • :filter - An optional function which takes a record and returns a boolean, true if the record is desired in pagination. Default is nil where all records (in the selected prefilter) will be included.
  • :prefilter - Two-element tuple, indicating the field name and value for the prefiltered index to be used. Default is nil, indicating that the index with the non-prefiltered, full list of records should be used.
  • :prepare - An optional function which takes a record and returns a new record to use -- both for the filter function and in the result.

# :fetch_cursor_value_fun function of arity 2 to lookup cursor values on returned records. # Defaults to Paginator.default_fetch_cursor_value/2 # :include_total_count - Set this to true to return the total number of # records matching the query. Note that this number will be capped by # :total_count_limit. Defaults to false. # :total_count_primary_key_field - Running count queries on specified column of the table # :limit - Limits the number of records returned per page. Note that this # number will be capped by :maximum_limit. Defaults to 50. # :maximum_limit - Sets a maximum cap for :limit. This option can be useful when :limit # is set dynamically (e.g from a URL param set by a user) but you still want to # enfore a maximum. Defaults to 500. # :sort_direction - The direction used for sorting. Defaults to :asc. # It is preferred to set the sorting direction per field in :cursor_fields. # * :total_count_limit - Running count queries on tables with a large number # of records is expensive so it is capped by default. Can be set to :infinity # in order to count all the records. Defaults to 10,000.