Skip to content

Commit 527d410

Browse files
committed
✨ Add partial updates to Notion plugin
1 parent abbb833 commit 527d410

File tree

3 files changed

+2
-18
lines changed

3 files changed

+2
-18
lines changed

plugins/notion/database_query.go

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func databaseTable(args rpc.TableCreatorArgs) (rpc.Table, *rpc.DatabaseSchema, e
156156
HandlesInsert: true,
157157
HandlesUpdate: true,
158158
HandlesDelete: true,
159+
PartialUpdate: true,
159160
Columns: rpcColumns,
160161
HandleOffset: false,
161162
PrimaryKey: pkIndex,

plugins/notion/database_update.go

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,14 @@ package main
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
7-
"log"
86

97
"github.com/jomei/notionapi"
108
)
119

1210
func (t *table) Update(rows [][]interface{}) error {
13-
log.Printf("Updating %d rows", len(rows))
1411
for _, row := range rows {
1512
primaryKey, ok := row[0].(string)
16-
log.Printf("Cols: %v", t.columns)
17-
log.Printf("Updating page %s", primaryKey)
18-
log.Printf("Row: %v", row)
1913
if !ok {
2014
return fmt.Errorf("invalid page id: %v", row[0])
2115
}
@@ -48,19 +42,11 @@ func (t *table) Update(rows [][]interface{}) error {
4842
continue
4943
}
5044

51-
log.Printf("Updating %s: %v(%T)", colName, propValue, propValue)
52-
5345
pageUpdateRequest.Properties[colName] = propValue
5446

5547
}
5648

57-
marshaled, err := json.Marshal(pageUpdateRequest)
58-
if err != nil {
59-
return err
60-
}
61-
62-
log.Printf("Update request: %s", marshaled)
63-
_, err = t.client.Page.Update(context.Background(), notionapi.PageID(primaryKey), pageUpdateRequest)
49+
_, err := t.client.Page.Update(context.Background(), notionapi.PageID(primaryKey), pageUpdateRequest)
6450
if err != nil {
6551
return err
6652
}

plugins/notion/marshalling.go

-3
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ func marshal(value interface{}, to notionapi.PropertyConfig) notionapi.Property
308308
}
309309
// Split the date into start and end
310310
splitted := strings.Split(v, "/")
311-
log.Printf("splitted: %v", splitted)
312311
var start, end *notionapi.Date
313312
if len(splitted) > 0 {
314313
startParse, err := parseTime(splitted[0])
@@ -318,7 +317,6 @@ func marshal(value interface{}, to notionapi.PropertyConfig) notionapi.Property
318317
val := notionapi.Date(startParse)
319318
start = &val
320319
}
321-
log.Printf("start: %v", start)
322320
if len(splitted) > 1 {
323321
endParse, err := parseTime(splitted[1])
324322
if err != nil {
@@ -327,7 +325,6 @@ func marshal(value interface{}, to notionapi.PropertyConfig) notionapi.Property
327325
val := notionapi.Date(endParse)
328326
end = &val
329327
}
330-
log.Printf("end: %v", end)
331328

332329
return notionapi.DateProperty{
333330
Date: &notionapi.DateObject{

0 commit comments

Comments
 (0)