diff --git a/sync/service/postgres.go b/sync/service/postgres.go index a4d6599..3bf5ed3 100644 --- a/sync/service/postgres.go +++ b/sync/service/postgres.go @@ -113,13 +113,13 @@ func (p *Postgres) Updated(ks []item.Kind, t time.Time) ([]item.Item, error) { for rows.Next() { var i item.Item var recurNext sql.NullTime - var recurrerJSON []byte + var recurrerJSON sql.NullString if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil { return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err) } - if len(recurrerJSON) > 0 { + if recurrerJSON.Valid && recurrerJSON.String != "" { var recurrer item.Recur - if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil { + if err := json.Unmarshal([]byte(recurrerJSON.String), &recurrer); err != nil { return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err) } i.Recurrer = &recurrer @@ -149,11 +149,11 @@ func (p *Postgres) RecursBefore(date time.Time) ([]item.Item, error) { for rows.Next() { var i item.Item var recurNext sql.NullTime - var recurrerJSON []byte + var recurrerJSON sql.NullString if err := rows.Scan(&i.ID, &i.Kind, &i.Updated, &i.Deleted, &i.Body, &recurrerJSON, &recurNext); err != nil { return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err) } - if len(recurrerJSON) > 0 { + if recurrerJSON.Valid && recurrerJSON.String != "" { var recurrer item.Recur if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil { return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)