-
Notifications
You must be signed in to change notification settings - Fork 0
/
rowsscanner.go
45 lines (39 loc) · 2.17 KB
/
rowsscanner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package sqldb
// RowsScanner scans the values from multiple rows.
type RowsScanner interface {
// ScanSlice scans one value per row into one slice element of dest.
// dest must be a pointer to a slice with a row value compatible element type.
// In case of zero rows, dest will be set to nil and no error will be returned.
// In case of an error, dest will not be modified.
// It is an error to query more than one column.
ScanSlice(dest any) error
// ScanStructSlice scans every row into the struct fields of dest slice elements.
// dest must be a pointer to a slice of structs or struct pointers.
// In case of zero rows, dest will be set to nil and no error will be returned.
// In case of an error, dest will not be modified.
// Every mapped struct field must have a corresponding column in the query results.
ScanStructSlice(dest any) error
// ScanAllRowsAsStrings scans the values of all rows as strings.
// Byte slices will be interpreted as strings,
// nil (SQL NULL) will be converted to an empty string,
// all other types are converted with fmt.Sprint.
// If true is passed for headerRow, then a row
// with the column names will be prepended.
ScanAllRowsAsStrings(headerRow bool) (rows [][]string, err error)
// Columns returns the column names.
Columns() ([]string, error)
// ForEachRow will call the passed callback with a RowScanner for every row.
// In case of zero rows, no error will be returned.
ForEachRow(callback func(RowScanner) error) error
// ForEachRowCall will call the passed callback with scanned values or a struct for every row.
// If the callback function has a single struct or struct pointer argument,
// then RowScanner.ScanStruct will be used per row,
// else RowScanner.Scan will be used for all arguments of the callback.
// If the function has a context.Context as first argument,
// then the context of the query call will be passed on.
// The callback can have no result or a single error result value.
// If a non nil error is returned from the callback, then this error
// is returned immediately by this function without scanning further rows.
// In case of zero rows, no error will be returned.
ForEachRowCall(callback any) error
}