Optimize: code logic db.scanIntoStruct() (#5633)

This commit is contained in:
jesse.tang 2022-09-05 15:34:33 +08:00 committed by GitHub
parent d71caef7d9
commit f78f635fae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 22 deletions

View File

@ -66,9 +66,12 @@ func (db *DB) scanIntoStruct(rows Rows, reflectValue reflect.Value, values []int
db.RowsAffected++
db.AddError(rows.Scan(values...))
joinedSchemaMap := make(map[*schema.Field]interface{}, 0)
joinedSchemaMap := make(map[*schema.Field]interface{})
for idx, field := range fields {
if field != nil {
if field == nil {
continue
}
if len(joinFields) == 0 || joinFields[idx][0] == nil {
db.AddError(field.Set(db.Statement.Context, reflectValue, values[idx]))
} else {
@ -91,7 +94,6 @@ func (db *DB) scanIntoStruct(rows Rows, reflectValue reflect.Value, values []int
field.NewValuePool.Put(values[idx])
}
}
}
// ScanMode scan data mode
type ScanMode uint8