pageSize()

Learn: Pagination

Sets the maximum elements per page in paginated results.

Lazy loading:

Yes

Signature

pageSize(size: Int): Set<A>

Description

The pageSize() method sets the maximum elements per page in paginated results.

If a subsequent page is available, the result includes an after cursor. To iterate through paginated results, pass the after cursor to Set.paginate().

Method chaining

pageSize() should typically be the last method call in an FQL statement.

pageSize() only affects the rendering of a set, not subsequent operations. Methods chained to pageSize() access the entire calling set, not a page of results.

after cursor

Differences with paginate()

  • Returns an Object, not a Set.

  • Uses eager loading and fetches results instantly, even if the results aren’t returned or used. This can produce slower and more wasteful queries.

  • Isn’t compatible with Fauna client driver pagination methods.

  • Doesn’t support projection or set instance methods.

If you need to access an after cursor or paginated results within an FQL query, use paginate(). Otherwise, you should use pageSize().

Parameters

Parameter Type Required Description

size

Int

Yes

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

Return value

Type Description

Set

Set that includes the following field:

after

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

Examples

// Calls `pageSize()` with a size of `2`.
Product.all().pageSize(2)
{
  // The returned set contains two elements or fewer.
  data: [
    {
      id: "393605620096303168",
      coll: Product,
      ts: Time("2099-03-28T12:53:40.750Z"),
      name: "limes",
      ...
    },
    {
      id: "393605620102594624",
      coll: Product,
      ts: Time("2099-03-28T12:53:40.750Z"),
      name: "cilantro",
      ...
    }
  ],
  after: "hdaExad..."
}

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!