Skip to content

Commit

Permalink
fetch all entries from notion database
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuxu committed Aug 6, 2023
1 parent b83a7a1 commit 938ee61
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/notion-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @julianjark/notion-client

## 0.9.0

### Minor Changes

- fetch all entries from notion database

## 0.8.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/notion-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@julianjark/notion-client",
"version": "0.8.0",
"version": "0.9.0",
"description": "Helper client library Notion API",
"author": "Julian Jark",
"license": "ISC",
Expand Down
22 changes: 22 additions & 0 deletions packages/notion-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,30 @@ export const getDatabasePages =
database_id: databaseId,
sorts,
filter,
page_size: 100,
});

const results: Awaited<
ReturnType<typeof notion.databases.query>
>["results"] = [];

let cursor: string | undefined;
const shouldContinue = true;
while (shouldContinue) {
const response = await notion.databases.query({
database_id: databaseId,
sorts,
filter,
page_size: 100,
start_cursor: cursor,
});
results.push(...results);
if (!response.next_cursor) {
break;
}
cursor = response.next_cursor;
}

return response.results.filter(isPageObjectResponse);
};

Expand Down
11 changes: 11 additions & 0 deletions packages/notion-cms/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @julianjark/notion-cms

## 0.12.0

### Minor Changes

- fetch all entries from notion database

### Patch Changes

- Updated dependencies
- @julianjark/notion-client@0.9.0

## 0.11.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/notion-cms/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@julianjark/notion-cms",
"version": "0.11.1",
"version": "0.12.0",
"description": "CMS abstraction for Notion",
"author": "Julian Jark",
"license": "ISC",
Expand Down

0 comments on commit 938ee61

Please sign in to comment.