DDD.Slice (vicander v0.1.1)

Copy Markdown View Source

A window of a listing that continues from a cursor (keyset pagination). Returned by slice/1 on repository adapters and projections:

{:ok, slice} = ListSummary.slice(order: [asc: :title], limit: 20)
{:ok, next} = ListSummary.slice(order: [asc: :title], limit: 20, after: slice.next_cursor)

There is no OFFSET, so page 500 costs the same as page 1, and rows added or removed while someone pages through don't shift what they see. next_cursor is nil on the last slice. A cursor is opaque: it is only valid with the :order it came from, and the order's fields should not be NULL (the primary key is always added as the last tie-breaker).

Summary

Functions

True when there is a slice after this one.

Types

t()

@type t() :: %DDD.Slice{
  entries: [term()],
  limit: pos_integer(),
  next_cursor: String.t() | nil
}

Functions

has_next?(slice)

@spec has_next?(t()) :: boolean()

True when there is a slice after this one.