Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS-2634] Document Client.paginate() #255

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -276,6 +277,42 @@ Example output:
}
```

## Pagination

By default, FQL paginates returned sets that contain more than 16 items.
Use the `Client.paginate()` method to iterate through pages of results.
jrodewig marked this conversation as resolved.
Show resolved Hide resolved

`Client.paginate()` accepts the same [query options](#query-options) as
`Client.query()`.

Change the default items per page using FQL's `<set>.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<QueryValue> = client.paginate(query, options);

for await (const products of pages) {
for (const product of products) {
console.log(product)
}
}

client.close();
```


## Event Streaming (beta)

Expand Down
Loading