fix: Handle null recurrer values consistently in PostgreSQL methods

This commit is contained in:
Erik Winter (aider) 2024-12-21 14:05:04 +01:00
parent 7570f49581
commit fc2a0e32cf
1 changed files with 5 additions and 5 deletions

View File

@ -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)