From 899e9f0e50ba6dbfb4e35dc1ea1bb0b319b66477 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 29 Sep 2021 21:16:26 +0300 Subject: [PATCH] dialect/sql: wraps the sql.Rows with ColumnScanner interface --- dialect/sql/driver.go | 14 +++++++++++++- dialect/sql/scan.go | 9 --------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dialect/sql/driver.go b/dialect/sql/driver.go index 49cef7f39..6f79be8dd 100644 --- a/dialect/sql/driver.go +++ b/dialect/sql/driver.go @@ -132,7 +132,7 @@ var _ dialect.Driver = (*Driver)(nil) type ( // Rows wraps the sql.Rows to avoid locks copy. - Rows struct{ *sql.Rows } + Rows struct{ ColumnScanner } // Result is an alias to sql.Result. Result = sql.Result // NullBool is an alias to sql.NullBool. @@ -165,3 +165,15 @@ func (n *NullScanner) Scan(value interface{}) error { } return nil } + +// ColumnScanner is the interface that wraps the standard +// sql.Rows methods used for scanning database rows. +type ColumnScanner interface { + Close() error + ColumnTypes() ([]*sql.ColumnType, error) + Columns() ([]string, error) + Err() error + Next() bool + NextResultSet() bool + Scan(dest ...interface{}) error +} diff --git a/dialect/sql/scan.go b/dialect/sql/scan.go index 6cfa01f0d..12f3a5835 100644 --- a/dialect/sql/scan.go +++ b/dialect/sql/scan.go @@ -12,15 +12,6 @@ import ( "strings" ) -// ColumnScanner is the interface that wraps the -// four sql.Rows methods used for scanning. -type ColumnScanner interface { - Next() bool - Scan(...interface{}) error - Columns() ([]string, error) - Err() error -} - // ScanOne scans one row to the given value. It fails if the rows holds more than 1 row. func ScanOne(rows ColumnScanner, v interface{}) error { columns, err := rows.Columns()