fix: Handle null recurrer values consistently in PostgreSQL methods
This commit is contained in:
parent
7570f49581
commit
fc2a0e32cf
|
@ -113,13 +113,13 @@ func (p *Postgres) Updated(ks []item.Kind, t time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i item.Item
|
var i item.Item
|
||||||
var recurNext sql.NullTime
|
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 {
|
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)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
if len(recurrerJSON) > 0 {
|
if recurrerJSON.Valid && recurrerJSON.String != "" {
|
||||||
var recurrer item.Recur
|
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)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
i.Recurrer = &recurrer
|
i.Recurrer = &recurrer
|
||||||
|
@ -149,11 +149,11 @@ func (p *Postgres) RecursBefore(date time.Time) ([]item.Item, error) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var i item.Item
|
var i item.Item
|
||||||
var recurNext sql.NullTime
|
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 {
|
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)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
}
|
}
|
||||||
if len(recurrerJSON) > 0 {
|
if recurrerJSON.Valid && recurrerJSON.String != "" {
|
||||||
var recurrer item.Recur
|
var recurrer item.Recur
|
||||||
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
if err := json.Unmarshal(recurrerJSON, &recurrer); err != nil {
|
||||||
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
return nil, fmt.Errorf("%w: %v", ErrPostgresFailure, err)
|
||||||
|
|
Loading…
Reference in New Issue