MCPcopy
hub / github.com/rilldata/rill / MarshalJSON

Method MarshalJSON

runtime/resolver.go:323–352  ·  view source on GitHub ↗

MarshalJSON implements ResolverResult.

()

Source from the content-addressed store, hash-verified

321
322// MarshalJSON implements ResolverResult.
323func (r *driverResolverResult) MarshalJSON() ([]byte, error) {
324 defer func() {
325 r.closeErr = r.rows.Close()
326 }()
327 var out []map[string]any
328 for r.rows.Next() {
329 row := make(map[string]any)
330 err := r.rows.MapScan(row)
331 if err != nil {
332 return nil, err
333 }
334
335 ret, err := jsonval.ToValue(row, &runtimev1.Type{Code: runtimev1.Type_CODE_STRUCT, StructType: r.rows.Schema})
336 if err != nil {
337 return nil, err
338 }
339 row, ok := ret.(map[string]any)
340 if !ok {
341 return nil, fmt.Errorf("Resolver.MarshalJSON unexpected type %T", ret)
342 }
343 out = append(out, row)
344 }
345 if r.rows.Err() != nil {
346 return nil, r.rows.Err()
347 }
348 if out == nil { // fixes 'null' output when there are no rows
349 out = []map[string]any{}
350 }
351 return json.Marshal(out)
352}
353
354// NewMapsResolverResult creates a ResolverResult from a slice of maps.
355func NewMapsResolverResult(result []map[string]any, schema *runtimev1.StructType) ResolverResult {

Callers

nothing calls this directly

Calls 6

ToValueFunction · 0.92
CloseMethod · 0.65
NextMethod · 0.65
MapScanMethod · 0.65
ErrorfMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected