Scan with Rows interface

This commit is contained in:
Jinzhu 2022-03-29 18:14:29 +08:00
parent 6c827ff2e3
commit 9dd6ed9c65
2 changed files with 12 additions and 2 deletions

View File

@ -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
}

View File

@ -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()
@ -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))