Skip to content

Commit

Permalink
Merge pull request #4998 from weichou1229/postgres-null-reading
Browse files Browse the repository at this point in the history
feat: Allow null reading for Postgres
  • Loading branch information
cloudxxx8 authored Nov 8, 2024
2 parents e5d1445 + c31e431 commit b53759f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/pkg/infrastructure/postgres/reading.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ func queryReadings(ctx context.Context, connPool *pgxpool.Pool, sql string, args
}
reading = simpleReading
} else {
return reading, errors.NewCommonEdgeX(errors.KindServerError, "failed to convert reading to none of BinaryReading/ObjectReading/SimpleReading structs", nil)
// reading type is NullReading
nullReading := model.NullReading{
BaseReading: baseReading,
Value: nil,
}
reading = nullReading
}

return reading, nil
Expand Down Expand Up @@ -348,6 +353,10 @@ func addReadingsInTx(tx pgx.Tx, readings []model.Reading, eventId string) error
BaseReading: baseReading,
SimpleReading: dbModels.SimpleReading{Value: &contractReadingModel.Value},
}
case model.NullReading:
readingDBModel = dbModels.Reading{
BaseReading: baseReading,
}
default:
return errors.NewCommonEdgeX(errors.KindContractInvalid, "failed to convert reading to none of BinaryReading/ObjectReading/SimpleReading structs", nil)
}
Expand Down

0 comments on commit b53759f

Please sign in to comment.