View Source Fob (Fob v1.0.1)

A keyset pagination library for Ecto queries

Keyset pagination works by filtering a data set with Ecto.Query.where/3s rather than Ecto.Query.offset/3.

Fob requires that any queryables are ordered by a unique column as the last ordering condition. Other non-unique columns may be ordered by as well, but the last Ecto.Query.order_by/3 must be unique.

Link to this section Summary

Functions

Limits a queryable to return records between two page break boundaries

Returns the page breaks for a record

Link to this section Functions

Link to this function

between_bounds(queryable, start, stop)

View Source (since 0.1.0)
@spec between_bounds(
  Ecto.Queryable.t(),
  [Fob.PageBreak.t()] | nil,
  [Fob.PageBreak.t()] | nil
) :: Ecto.Query.t()

Limits a queryable to return records between two page break boundaries

Link to this function

next_page(queryable, page_breaks, page_size)

View Source (since 0.1.0)
@spec next_page(
  Ecto.Queryable.t(),
  [Fob.PageBreak.t()] | nil,
  pos_integer() | :infinity
) :: Ecto.Query.t()

Limits an Ecto.Queryable to the next page of data

page_breaks are used to add Ecto.Query.where/3 filters to the query which limit the query to the next page. page_size translates to a Ecto.Query.limit/2.

Link to this function

page_breaks(queryable, record)

View Source (since 0.1.0)
@spec page_breaks(Ecto.Queryable.t(), record :: map() | nil) ::
  [Fob.PageBreak.t()] | nil

Returns the page breaks for a record

The query does not need to be limited by next_page/3 or between_bounds/3: the query only needs to have the Ecto.Query.order_by/3s used in the query to get the record.

examples

Examples

iex> records = MyApp.Repo.all(Fob.next_page(query, current_page_breaks, page_size))
iex> next_page_breaks = Fob.page_breaks(query, List.last(records))