From c31e4310fcd504ae1da8f47206d4caf8c29158e4 Mon Sep 17 00:00:00 2001 From: bruce <weichou1229@gmail.com> Date: Fri, 8 Nov 2024 11:52:06 +0800 Subject: [PATCH] feat: Allow null reading for Postgres Allow null reading for Postgres Signed-off-by: bruce <weichou1229@gmail.com> --- internal/pkg/infrastructure/postgres/reading.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/pkg/infrastructure/postgres/reading.go b/internal/pkg/infrastructure/postgres/reading.go index 33d4e4771a..20a0f28556 100644 --- a/internal/pkg/infrastructure/postgres/reading.go +++ b/internal/pkg/infrastructure/postgres/reading.go @@ -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 @@ -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) }