diff --git a/README.md b/README.md index d6ab899a..f695c0f2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ See the [Fauna Documentation](https://docs.fauna.com/fauna/current/) for additio - [Typescript support](#typescript-support) - [Query options](#query-options) - [Query statistics](#query-statistics) + - [Pagination](#pagination) - [Event Streaming (beta)](#event-streaming-beta) - [Client configuration](#client-configuration) - [Environment variables](#environment-variables) @@ -276,6 +277,41 @@ Example output: } ``` +## Pagination + +Use the `Client.paginate()` method to iterate sets that contain more than one page of results. + +`Client.paginate()` accepts the same [query options](#query-options) as +`Client.query()`. + +Change the default items per page using FQL's `.pageSize()` method. + +```typescript +import { fql, Client, type SetIterator, type QueryValue } from "fauna"; + +const client = new Client(); + +// Adjust `pageSize()` size as needed. +const query = fql` + Product + .byName("limes") + .pageSize(60) { description }`; + +const options = { + query_timeout_ms: 60_000, +}; + +const pages: SetIterator = client.paginate(query, options); + +for await (const products of pages) { + for (const product of products) { + console.log(product) + } +} + +client.close(); +``` + ## Event Streaming (beta)