|
|
@@ -275,7 +275,7 @@ func (result Result) ColumnValueFloat64(columnName string) float64 {
|
|
|
|
|
|
// PostDealFunc 后处理函数
|
|
|
// output为解析时传入的实体的指针
|
|
|
-type PostDealFunc func(output any) error
|
|
|
+type PostDealFunc func(i int, result Result, output any) error
|
|
|
|
|
|
// ParseSqlResult 解析查询结果
|
|
|
// 参数:
|
|
|
@@ -340,7 +340,7 @@ func ParseSqlResultWithColumnFunc(input any, output any, columnName string, post
|
|
|
return errors.New("输出不是slice,输入需要是sql.Result")
|
|
|
}
|
|
|
|
|
|
- return parseSqlSingleFunc(result, output, columnName, postDealFunc)
|
|
|
+ return parseSqlSingleFunc(0, result, output, columnName, postDealFunc)
|
|
|
}
|
|
|
|
|
|
// 输出是slice,需要遍历处理
|
|
|
@@ -351,19 +351,19 @@ func ParseSqlResultWithColumnFunc(input any, output any, columnName string, post
|
|
|
|
|
|
outputEntities := reflect.MakeSlice(outputElemType, 0, 0)
|
|
|
|
|
|
- for _, result := range results {
|
|
|
+ for i, result := range results {
|
|
|
var outputEntityValue reflect.Value
|
|
|
|
|
|
// slice子类型判断
|
|
|
if outputElemType.Elem().Kind() == reflect.Pointer {
|
|
|
outputEntityValue = reflect.New(outputElemType.Elem().Elem())
|
|
|
- err := parseSqlSingleFunc(result, outputEntityValue.Interface(), columnName, postDealFunc)
|
|
|
+ err := parseSqlSingleFunc(i, result, outputEntityValue.Interface(), columnName, postDealFunc)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
} else {
|
|
|
outputEntityValue = reflect.New(outputElemType.Elem()).Elem()
|
|
|
- err := parseSqlSingleFunc(result, outputEntityValue.Addr().Interface(), columnName, postDealFunc)
|
|
|
+ err := parseSqlSingleFunc(i, result, outputEntityValue.Addr().Interface(), columnName, postDealFunc)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -378,7 +378,7 @@ func ParseSqlResultWithColumnFunc(input any, output any, columnName string, post
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func parseSqlSingleFunc(result Result, output any, columnName string, postDealFunc PostDealFunc) error {
|
|
|
+func parseSqlSingleFunc(resultIndex int, result Result, output any, columnName string, postDealFunc PostDealFunc) error {
|
|
|
outputValue := reflectutils.PointerValueElem(reflect.ValueOf(output))
|
|
|
outputKind := reflectutils.GroupValueKind(outputValue)
|
|
|
|
|
|
@@ -437,7 +437,7 @@ func parseSqlSingleFunc(result Result, output any, columnName string, postDealFu
|
|
|
}
|
|
|
|
|
|
if postDealFunc != nil {
|
|
|
- err := postDealFunc(output)
|
|
|
+ err := postDealFunc(resultIndex, result, output)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|