View Source Fob (Fob v1.0.3)
A keyset pagination library for Ecto queries
Keyset pagination works by filtering a data set with Ecto.Query.where/3
s
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
Limits an Ecto.Queryable
to the next page of data
Returns the page breaks for a record
Link to this section Functions
@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
@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
.
@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/3
s 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))