feat: 去掉了批量查询时,结果为空的报错
This commit is contained in:
10
mapping.go
10
mapping.go
@@ -247,10 +247,6 @@ func (b *Mapper) ScanRowsWithContext(ctx context.Context, target any, rows *sql.
|
||||
// 将新实例添加到slice中
|
||||
vf.Set(reflect.Append(vf, newStruct))
|
||||
}
|
||||
|
||||
if vf.Len() == 0 { // 如果slice为空,返回 sql.ErrNoRows
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return errors.New("target must be a pointer to a struct or a slice of structs")
|
||||
@@ -277,11 +273,11 @@ func (b *Mapper) scanRow(target reflect.Value, rows *sql.Rows) error {
|
||||
dest := make([]interface{}, len(columns))
|
||||
for i, colName := range columns {
|
||||
// 拿到缓存的字段索引
|
||||
if idx, ok := mate.DBName2IndexCache[colName]; ok {
|
||||
dest[i] = target.FieldByIndex(idx).Addr().Interface()
|
||||
} else {
|
||||
idx, ok := mate.DBName2IndexCache[colName]
|
||||
if !ok {
|
||||
return fmt.Errorf("no corresponding field found for column %s", colName)
|
||||
}
|
||||
dest[i] = target.FieldByIndex(idx).Addr().Interface()
|
||||
}
|
||||
|
||||
// 扫描数据
|
||||
|
||||
Reference in New Issue
Block a user