Skip to content

ENG-651: Add pagination section #84

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

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
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
54 changes: 53 additions & 1 deletion read.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ const db = new Polybase({ defaultNamespace: "your-namespace" });
const collectionReference = db.collection("cities");

async function getRecord () {
const { data, block } = await collectionReference.record("id").get();
const record = await collectionReference.record("id").get();

// Get data from the record
const { data } = record; // or const data = record.data

// Record is CollectionRecordResponse instance, so you can also get again to refresh
const updatedRecord = record.get();
}
```

Expand Down Expand Up @@ -74,6 +80,12 @@ const collectionReference = db.collection("cities");

export async function listRecordsWithFilter () {
const records = await collectionReference.where("country", "==", "UK").get();

// Array of records is available under the data property
const { data, cursor } = records;

// Records is QueryResponse, so we can use it to get the next page of results
await records.next();
}

```
Expand Down Expand Up @@ -110,3 +122,43 @@ const collectionReference = db
}
);
```

## Pagination

You can paginate through your results using the cursor returned from the
`.get()` method, or by using the built-in `.next()`

### Pagination with cursor

Use the cursor response with `.before()` and `.after()` to paginate through
collection data.

```js
const db = new Polybase({ defaultNamespace: "your-namespace" });
const collectionReference = await db.collection("cities");

// First page
const { data, cursor } = await collectionReference.get();

// Next page
const next = await collectionReference.after(cursor.after).get();

// Previous page
const previous = await collectionReference.before(cursor.before).get();
```

### Pagination with next() or previous()

To simplify this process, a `next()` and `previous()` helper method is provided on the response.

```js
const db = new Polybase({ defaultNamespace: "your-namespace" });
const collectionReference = await db.collection("cities");

// First page
const first = await collectionReference.get();

// Next pages
const second = await first.next();
const third = await second.next();
```