From faf9d6c0b03471036d23386141c730bb7650568f Mon Sep 17 00:00:00 2001 From: Nathan <148575555+nathan-artie@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:40:11 -0700 Subject: [PATCH] Update --- clients/bigquery/cast.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/clients/bigquery/cast.go b/clients/bigquery/cast.go index 321fc0491..badb36e11 100644 --- a/clients/bigquery/cast.go +++ b/clients/bigquery/cast.go @@ -85,19 +85,15 @@ func castColVal(colVal any, colKind columns.Column, additionalDateFmts []string) return fmt.Sprint(colVal), nil } +// EncodeStructToJSONString takes a struct as either a string or Go object and encodes it into a JSON string. +// Structs from relational and Mongo are different. +// MongoDB will return the native objects back such as `map[string]any{"hello": "world"}` +// Relational will return a string representation of the struct such as `{"hello": "world"}` func EncodeStructToJSONString(value any) (string, error) { - if strings.Contains(fmt.Sprint(value), constants.ToastUnavailableValuePlaceholder) { - return fmt.Sprintf(`{"key":"%s"}`, constants.ToastUnavailableValuePlaceholder), nil - } - - // Structs from relational and Mongo are different. - // MongoDB will return the native objects back such as `map[string]any{"hello": "world"}` - // Relational will return a string representation of the struct such as `{"hello": "world"}` if colValString, isOk := value.(string); isOk { - if colValString == "" { - return "", nil + if strings.Contains(colValString, constants.ToastUnavailableValuePlaceholder) { + return fmt.Sprintf(`{"key":"%s"}`, constants.ToastUnavailableValuePlaceholder), nil } - return colValString, nil } @@ -105,6 +101,5 @@ func EncodeStructToJSONString(value any) (string, error) { if err != nil { return "", fmt.Errorf("failed to marshal colVal: %w", err) } - return string(colValBytes), nil }