paginate()

Get the first page of Set values.

Signature

paginate(): Object<A>

paginate(size: Int): Object<A>

Description

The paginate() method gets the first page of size Set values. When size is omitted, the default page size is 16.

When the Set has more than size values, a pagination cursor is included as the last entry on the page. Use the Set.paginate() method with the provided cursor to sequentially access subsequent pages.

The pagination cursor is stable in the sense that pagination through a set is done for a fixed snapshot time, giving you a view of your data as it existed across the whole set at the instant you started paginating. For example, given set [a, b, c] when you start paginating, one item at a time, even if you delete item c after you started reading the set, item c is returned.

The exception is if the history is no longer available for the deleted item because history_days is set to the default value of 0 or is less than the minimum valid time needed. In that case, the deleted item is not returned with the paginated results and an error is returned:
Requested timestamp <time> less than minimum allowed timestamp..

A cursor is valid for history_days plus 15 minutes.

Parameters

Parameter Type Required Description

size

Int

Number of Set values to include in the returned page. The size parameter must be in the range 1 to 16000.

Return value

Type Description

Object that includes the following fields:

data

Array of values.

after

(optional) Cursor pointing to next page when more pages exist. The cursor is valid for history_days plus 15 minutes.

Examples

Apply a page size of two to the Set of all Product documents:

Letter.all().paginate(2)
{
  data: [
    {
      id: "101",
      coll: Letter,
      ts: Time("2022-11-18T21:23:43.310Z"),
      letter: "A",
      extra: "First"
    },
    {
      id: "102",
      coll: Letter,
      ts: Time("2022-11-18T21:23:43.310Z"),
      letter: "B",
      extra: "second"
    }
  ],
  after: "hs6DxoJmTGV0dGVygwAAZipudWxsKoJjYWxsgwAAZipudWxsKoMAAGYqbnVsbCqAgEoAAAAAAAAAZgQA9cGCGmN3998aGBSNAA=="
}

See also

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!