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)
| 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. |
| 33 | func 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 | |
| 56 | type scanHolders struct { |
| 57 | ptrs []any |
searching dependent graphs…