Skip to content

Commit 7bf6c7d

Browse files
authored
Move json null logic inline (#3594)
It's good when the conversion logic is not far away in some other file
1 parent 52591d5 commit 7bf6c7d

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

flow/connectors/postgres/cdc.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package connpostgres
22

33
import (
44
"context"
5+
"encoding/json"
56
"errors"
67
"fmt"
78
"log/slog"
@@ -324,8 +325,8 @@ func (p *PostgresCDCSource) decodeColumnData(
324325
return nil, fmt.Errorf("failed to unmarshal json: %w", err)
325326
}
326327
if parsedData == nil {
327-
// avoid confusing SQL null & JSON null by using struct{} as json null sentinel
328-
parsedData = model.JsonNull{}
328+
// avoid confusing SQL null & JSON null by using pre-marshaled value
329+
parsedData = json.RawMessage("null")
329330
}
330331
return p.parseFieldFromPostgresOID(dataType, typmod, true, protos.DBType_DBTYPE_UNKNOWN,
331332
parsedData, customTypeMapping, p.internalVersion)

flow/connectors/postgres/qrep_query_executor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package connpostgres
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"log/slog"
78
"maps"
@@ -379,8 +380,8 @@ func (qe *QRepQueryExecutor) mapRowToQRecord(
379380
return nil, fmt.Errorf("failed to unmarshal json: %w", err)
380381
}
381382
if values[i] == nil {
382-
// avoid confusing SQL null & JSON null by using struct{} as json null sentinel
383-
values[i] = model.JsonNull{}
383+
// avoid confusing SQL null & JSON null by using pre-marshaled value
384+
values[i] = json.RawMessage("null")
384385
}
385386
case pgtype.JSONArrayOID, pgtype.JSONBArrayOID:
386387
var textArr pgtype.FlatArray[pgtype.Text]

flow/model/model.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ import (
1313
"github.com/PeerDB-io/peerdb/flow/shared/exceptions"
1414
)
1515

16-
type JsonNull struct{}
17-
18-
func (JsonNull) MarshalJSON() ([]byte, error) {
19-
return []byte("null"), nil
20-
}
21-
2216
type NameAndExclude struct {
2317
Exclude map[string]struct{}
2418
Name string

0 commit comments

Comments
 (0)