MCPcopy Index your code
hub / github.com/netdata/netdata / ScanTypedRows

Function ScanTypedRows

src/go/plugin/go.d/pkg/sqlquery/scan.go:33–54  ·  view source on GitHub ↗

ScanTypedRows scans all rows according to specs and returns normalized [][]any rows. The function intentionally does not call rows.Err(); callers keep control over that.

(rows RowScanner, specs []ScanColumnSpec)

Source from the content-addressed store, hash-verified

31// ScanTypedRows scans all rows according to specs and returns normalized [][]any rows.
32// The function intentionally does not call rows.Err(); callers keep control over that.
33func ScanTypedRows(rows RowScanner, specs []ScanColumnSpec) ([][]any, error) {
34 data := make([][]any, 0, 500)
35 holders := makeScanHolders(specs)
36
37 for rows.Next() {
38 if err := rows.Scan(holders.ptrs...); err != nil {
39 return nil, fmt.Errorf("scan row: %w", err)
40 }
41
42 row := make([]any, len(specs))
43 for i := range holders.ptrs {
44 value, ok := holders.value(i)
45 if ok && specs[i].Transform != nil {
46 value = specs[i].Transform(value)
47 }
48 row[i] = value
49 }
50 data = append(data, row)
51 }
52
53 return data, nil
54}
55
56type scanHolders struct {
57 ptrs []any

Callers 1

TestScanTypedRowsFunction · 0.85

Calls 5

makeScanHoldersFunction · 0.85
NextMethod · 0.65
ScanMethod · 0.65
ErrorfMethod · 0.65
valueMethod · 0.65

Tested by 1

TestScanTypedRowsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…