diff --git a/sync/service/postgres.go b/sync/service/postgres.go index b53ed67..863445a 100644 --- a/sync/service/postgres.go +++ b/sync/service/postgres.go @@ -2,6 +2,7 @@ package main import ( "database/sql" + "encoding/json" "errors" "fmt" "strings" @@ -58,7 +59,16 @@ func NewPostgres(host, port, dbname, user, password string) (*Postgres, error) { } func (p *Postgres) Update(item item.Item, ts time.Time) error { - _, err := p.db.Exec(` + var recurrerJSON []byte + var err error + if item.Recurrer != nil { + recurrerJSON, err = json.Marshal(item.Recurrer) + if err != nil { + return fmt.Errorf("%w: %v", ErrPostgresFailure, err) + } + } + + _, err = p.db.Exec(` INSERT INTO items (id, kind, updated, deleted, body, recurrer, recur_next) VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (id) DO UPDATE @@ -68,7 +78,7 @@ func (p *Postgres) Update(item item.Item, ts time.Time) error { body = EXCLUDED.body, recurrer = EXCLUDED.recurrer, recur_next = EXCLUDED.recur_next`, - item.ID, item.Kind, ts, item.Deleted, item.Body, item.Recurrer, item.RecurNext) + item.ID, item.Kind, ts, item.Deleted, item.Body, recurrerJSON, item.RecurNext) if err != nil { return fmt.Errorf("%w: %v", ErrPostgresFailure, err) }