refactor: use typescript
Signed-off-by: Vojtěch Mareš <vojtech@mares.cz>
This commit is contained in:
parent
0a9d12b777
commit
333969a4fa
4 changed files with 338 additions and 7 deletions
|
|
@ -1,4 +0,0 @@
|
|||
import { Client } from "@notionhq/client";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
41
src/main.mts
Normal file
41
src/main.mts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Client } from "@notionhq/client";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
await main();
|
||||
|
||||
async function main() {
|
||||
const notion = new Client({
|
||||
auth: process.env.NOTION_KEY as string,
|
||||
});
|
||||
|
||||
const databaseID = process.env.DATABASE_ID as string;
|
||||
|
||||
const pages = await queryDatabase(notion, databaseID);
|
||||
|
||||
console.log(pages);
|
||||
}
|
||||
|
||||
async function queryDatabase(notion: Client, databaseID: string) {
|
||||
const pages: any[] = [];
|
||||
let cursor: string | undefined = undefined;
|
||||
|
||||
const shouldContinue = true;
|
||||
while (shouldContinue) {
|
||||
const { results, next_cursor } = await notion.databases.query({
|
||||
database_id: databaseID,
|
||||
start_cursor: cursor,
|
||||
});
|
||||
|
||||
pages.push(...results as never[]);
|
||||
|
||||
if (!next_cursor) {
|
||||
break;
|
||||
}
|
||||
|
||||
cursor = next_cursor;
|
||||
}
|
||||
|
||||
return pages;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue