Skip to content

Commit b4be039

Browse files
committed
added RowScanner.Columns and RowsScanner.Columns
1 parent 4384a2b commit b4be039

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

Diff for: errors.go

+8
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ func (e rowScannerWithError) ScanStrings() ([]string, error) {
226226
return nil, e.err
227227
}
228228

229+
func (e rowScannerWithError) Columns() ([]string, error) {
230+
return nil, e.err
231+
}
232+
229233
// RowsScannerWithError
230234

231235
// RowsScannerWithError returns a dummy RowsScanner
@@ -246,6 +250,10 @@ func (e rowsScannerWithError) ScanStructSlice(dest any) error {
246250
return e.err
247251
}
248252

253+
func (e rowsScannerWithError) Columns() ([]string, error) {
254+
return nil, e.err
255+
}
256+
249257
func (e rowsScannerWithError) ScanAllRowsAsStrings(headerRow bool) ([][]string, error) {
250258
return nil, e.err
251259
}

Diff for: impl/rowscanner.go

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func (s *RowScanner) ScanStrings() ([]string, error) {
7171
return ScanStrings(s.rows)
7272
}
7373

74+
func (s *RowScanner) Columns() ([]string, error) {
75+
return s.rows.Columns()
76+
}
77+
7478
// CurrentRowScanner calls Rows.Scan without Rows.Next and Rows.Close
7579
type CurrentRowScanner struct {
7680
Rows Rows
@@ -93,6 +97,10 @@ func (s CurrentRowScanner) ScanStrings() ([]string, error) {
9397
return ScanStrings(s.Rows)
9498
}
9599

100+
func (s CurrentRowScanner) Columns() ([]string, error) {
101+
return s.Rows.Columns()
102+
}
103+
96104
// SingleRowScanner always uses the same Row
97105
type SingleRowScanner struct {
98106
Row Row
@@ -114,3 +122,7 @@ func (s SingleRowScanner) ScanValues() ([]any, error) {
114122
func (s SingleRowScanner) ScanStrings() ([]string, error) {
115123
return ScanStrings(s.Row)
116124
}
125+
126+
func (s SingleRowScanner) Columns() ([]string, error) {
127+
return s.Row.Columns()
128+
}

Diff for: impl/rowsscanner.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ func (s *RowsScanner) ScanStructSlice(dest any) error {
3939
return nil
4040
}
4141

42+
func (s *RowsScanner) Columns() ([]string, error) {
43+
return s.rows.Columns()
44+
}
45+
4246
func (s *RowsScanner) ScanAllRowsAsStrings(headerRow bool) (rows [][]string, err error) {
4347
cols, err := s.rows.Columns()
4448
if err != nil {

Diff for: rowscanner.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ type RowScanner interface {
1818
// nil (SQL NULL) will be converted to an empty string,
1919
// all other types are converted with fmt.Sprint(src).
2020
ScanStrings() ([]string, error)
21+
22+
// Columns returns the column names.
23+
Columns() ([]string, error)
2124
}

Diff for: rowsscanner.go

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ type RowsScanner interface {
2424
// with the column names will be prepended.
2525
ScanAllRowsAsStrings(headerRow bool) (rows [][]string, err error)
2626

27+
// Columns returns the column names.
28+
Columns() ([]string, error)
29+
2730
// ForEachRow will call the passed callback with a RowScanner for every row.
2831
// In case of zero rows, no error will be returned.
2932
ForEachRow(callback func(RowScanner) error) error

0 commit comments

Comments
 (0)