Skip to content

Commit

Permalink
Scan with Rows interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Mar 29, 2022
1 parent 6c827ff commit 9dd6ed9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ type Valuer interface {
type GetDBConnector interface {
GetDBConn() (*sql.DB, error)
}

// Rows rows interface
type Rows interface {
Columns() ([]string, error)
ColumnTypes() ([]*sql.ColumnType, error)
Next() bool
Scan(dest ...interface{}) error
Err() error
Close() error
}
4 changes: 2 additions & 2 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func scanIntoMap(mapValue map[string]interface{}, values []interface{}, columns
}
}

func (db *DB) scanIntoStruct(rows *sql.Rows, reflectValue reflect.Value, values []interface{}, fields []*schema.Field, joinFields [][2]*schema.Field) {
func (db *DB) scanIntoStruct(rows Rows, reflectValue reflect.Value, values []interface{}, fields []*schema.Field, joinFields [][2]*schema.Field) {
for idx, field := range fields {
if field != nil {
values[idx] = field.NewValuePool.Get()
Expand Down Expand Up @@ -99,7 +99,7 @@ const (
)

// Scan scan rows into db statement
func Scan(rows *sql.Rows, db *DB, mode ScanMode) {
func Scan(rows Rows, db *DB, mode ScanMode) {
var (
columns, _ = rows.Columns()
values = make([]interface{}, len(columns))
Expand Down

0 comments on commit 9dd6ed9

Please sign in to comment.