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

Function unmarshalRowField

backend/api/mcp/tool_query.go:273–299  ·  view source on GitHub ↗

unmarshalRowField decodes a single protojson RowValue oneof field.

(key string, val json.RawMessage)

Source from the content-addressed store, hash-verified

271
272// unmarshalRowField decodes a single protojson RowValue oneof field.
273func unmarshalRowField(key string, val json.RawMessage) (any, bool) {
274 switch key {
275 case "nullValue":
276 return nil, true
277 case "boolValue":
278 return unmarshalAs[bool](val)
279 case "stringValue":
280 return unmarshalAs[string](val)
281 case "int32Value":
282 return unmarshalAs[int32](val)
283 case "int64Value":
284 // protojson encodes int64 as string.
285 if v, ok := unmarshalAs[string](val); ok {
286 return v, true
287 }
288 return unmarshalAs[int64](val)
289 case "doubleValue", "floatValue":
290 return unmarshalAs[float64](val)
291 case "timestampValue", "timestampTzValue":
292 return unmarshalTimestamp(val)
293 default:
294 if v, ok := unmarshalAs[string](val); ok {
295 return v, true
296 }
297 return string(val), true
298 }
299}
300
301// unmarshalAs attempts to decode JSON into the given type.
302func unmarshalAs[T any](val json.RawMessage) (T, bool) {

Callers 1

flattenRowValueFunction · 0.85

Calls 1

unmarshalTimestampFunction · 0.85

Tested by

no test coverage detected