dstotijn / go-notion

Go client for the Notion API.
MIT License
379 stars 40 forks source link

Impossible to create an empty DatabaseQueryFilter to fetch all rows from a database #14

Closed AsFal closed 3 years ago

AsFal commented 3 years ago

Description

Impossible to create a DatabaseQuery with an empty DatabseQueryFilter. Fields that do not have empty values (such as embedded structs) cannot be omitted. Source

To Reproduce

Populate your environment variables with valid values for NOTION_SECRET_API_KEY and NOTION_DATABASE_ID and run the following code.

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/dstotijn/go-notion"
)

func main() {
    client := notion.NewClient(os.Getenv("NOTION_SECRET_API_KEY"))
    rows, err := client.QueryDatabase(context.Background(), os.Getenv("NOTION_DATABASE_ID"), &notion.DatabaseQuery{
        PageSize: 10,
    })
    fmt.Println("======= ERROR ======")
    fmt.Println(err)
    fmt.Println("======= ROWS ======")
    fmt.Println(rows)
}

Given the following table

Screen Shot 2021-05-24 at 10 10 24 PM

I go the following error

Screen Shot 2021-05-24 at 10 11 24 PM
maksim77 commented 3 years ago

Just specify nil instead &notion.DatabaseQuery

AsFal commented 3 years ago

Specifying nil for &notion.DatabaseQuery wouldn't allow the use of an empty filter with custom Sort, StartCursor, or PageSize values. This would prevent fetching all the entries from a database with more than 100 entries given the page size limit.

dstotijn commented 3 years ago

Fixed and released in v0.3.2.