MCPcopy Create free account
hub / github.com/bytebase/bytebase / convertValueToBytesInCSV

Function convertValueToBytesInCSV

backend/component/export/csv.go:49–84  ·  view source on GitHub ↗
(value *v1pb.RowValue)

Source from the content-addressed store, hash-verified

47}
48
49func convertValueToBytesInCSV(value *v1pb.RowValue) []byte {
50 if value == nil || value.Kind == nil {
51 return []byte("")
52 }
53 switch value.Kind.(type) {
54 case *v1pb.RowValue_StringValue:
55 return quoteCSVString(value.GetStringValue())
56 case *v1pb.RowValue_Int32Value:
57 return []byte(strconv.FormatInt(int64(value.GetInt32Value()), 10))
58 case *v1pb.RowValue_Int64Value:
59 return []byte(strconv.FormatInt(value.GetInt64Value(), 10))
60 case *v1pb.RowValue_Uint32Value:
61 return []byte(strconv.FormatUint(uint64(value.GetUint32Value()), 10))
62 case *v1pb.RowValue_Uint64Value:
63 return []byte(strconv.FormatUint(value.GetUint64Value(), 10))
64 case *v1pb.RowValue_FloatValue:
65 return []byte(strconv.FormatFloat(float64(value.GetFloatValue()), 'f', -1, 32))
66 case *v1pb.RowValue_DoubleValue:
67 return []byte(strconv.FormatFloat(value.GetDoubleValue(), 'f', -1, 64))
68 case *v1pb.RowValue_BoolValue:
69 return []byte(strconv.FormatBool(value.GetBoolValue()))
70 case *v1pb.RowValue_BytesValue:
71 hexStr := "0x" + hex.EncodeToString(value.GetBytesValue())
72 return quoteCSVString(hexStr)
73 case *v1pb.RowValue_NullValue:
74 return []byte("")
75 case *v1pb.RowValue_TimestampValue:
76 return quoteCSVString(formatTimestamp(value.GetTimestampValue()))
77 case *v1pb.RowValue_TimestampTzValue:
78 return quoteCSVString(formatTimestampTz(value.GetTimestampTzValue()))
79 case *v1pb.RowValue_ValueValue:
80 return convertValueValueToBytes(value.GetValueValue())
81 default:
82 return []byte("")
83 }
84}
85
86// quoteCSVString wraps a string in double quotes and escapes internal quotes.
87func quoteCSVString(s string) []byte {

Callers 1

CSVToWriterFunction · 0.85

Calls 15

quoteCSVStringFunction · 0.85
formatTimestampTzFunction · 0.85
convertValueValueToBytesFunction · 0.85
GetStringValueMethod · 0.80
GetInt32ValueMethod · 0.80
GetInt64ValueMethod · 0.80
GetUint32ValueMethod · 0.80
GetUint64ValueMethod · 0.80
GetFloatValueMethod · 0.80
GetDoubleValueMethod · 0.80
GetBoolValueMethod · 0.80
GetBytesValueMethod · 0.80

Tested by

no test coverage detected