notion.notion.querydatabase
Home > @runlightyear/notion > Notion > queryDatabase
Notion.queryDatabase() method
Query a database
Signature:queryDatabase(props: QueryDatabaseProps): Promise<QueryDatabaseResponse>;
Parameters
Parameter | Type | Description |
---|---|---|
props | QueryDatabaseProps |
Promise<QueryDatabaseResponse>
Example 1
Query a database
import { defineAction } from "@runlightyear/lightyear";
import { Notion } from "@runlightyear/notion";
defineAction({
name: "queryDatabase",
title: "Query Database",
apps: ["notion"],
variables: ["databaseId"],
run: async ({ auths, variables }) => {
const notion = new Notion({
auth: auths.notion,
});
const response = await notion.queryDatabase({
databaseId: variables.databaseId!,
});
console.log("Query result: ", response.data);
},
});
Example 2
Query a database with filter
import { defineAction } from "@runlightyear/lightyear";
import { Notion } from "@runlightyear/notion";
defineAction({
name: "queryDatabaseWithFilter",
title: "Query Database With Filter",
apps: ["notion"],
variables: ["databaseId"],
run: async ({ auths, variables }) => {
const notion = new Notion({
auth: auths.notion,
});
const response = await notion.queryDatabase({
databaseId: variables.databaseId!,
filter: {
property: "Name",
richText: {
isNotEmpty: true,
},
},
});
console.log("Result: ", response.data);
},
});