2
0

Add RowScanner interface

This commit is contained in:
Jack Christensen
2022-04-30 12:49:12 -05:00
parent 01190e5d78
commit c1495aace0
3 changed files with 47 additions and 0 deletions
+13
View File
@@ -69,6 +69,12 @@ type Row interface {
Scan(dest ...any) error
}
// RowScanner scans an entire row at a time into the RowScanner.
type RowScanner interface {
// ScanRows scans the row.
ScanRow(rows Rows) error
}
// connRow implements the Row interface for Conn.QueryRow.
type connRow connRows
@@ -212,6 +218,13 @@ func (rows *connRows) Scan(dest ...any) error {
rows.fatal(err)
return err
}
if len(dest) == 1 {
if rc, ok := dest[0].(RowScanner); ok {
return rc.ScanRow(rows)
}
}
if len(fieldDescriptions) != len(dest) {
err := fmt.Errorf("number of field descriptions must equal number of destinations, got %d and %d", len(fieldDescriptions), len(dest))
rows.fatal(err)