|
@@ -40,8 +40,14 @@ func ParseSqlResult(input any, output any) error {
|
|
|
}
|
|
|
|
|
|
|
|
|
- if outputElemType.Kind() != reflect.Struct {
|
|
|
- return errors.New("输出实体slice应该为结构的slice指针")
|
|
|
+ if outputElemType.Kind() == reflect.Ptr {
|
|
|
+ if outputElemType.Elem().Kind() != reflect.Struct {
|
|
|
+ return errors.New("输出实体slice元素应该为结构或者结构指针")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if outputElemType.Kind() != reflect.Struct {
|
|
|
+ return errors.New("输出实体slice应该为结构或者结构指针")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -60,8 +66,15 @@ func ParseSqlResult(input any, output any) error {
|
|
|
|
|
|
for _, tableRow := range tableRows {
|
|
|
|
|
|
- outputEntityValue := reflect.New(outputElemType).Elem().Addr()
|
|
|
- outputEntity := outputEntityValue.Interface()
|
|
|
+ outputEntityValue := reflect.New(outputElemType).Elem()
|
|
|
+
|
|
|
+ var outputEntity any
|
|
|
+ if outputElemType.Kind() == reflect.Ptr {
|
|
|
+ outputEntityValue.Set(reflect.New(outputElemType.Elem()).Elem().Addr())
|
|
|
+ outputEntity = outputEntityValue.Interface()
|
|
|
+ } else {
|
|
|
+ outputEntity = outputEntityValue.Addr().Interface()
|
|
|
+ }
|
|
|
|
|
|
sqlResult, err := ParseSqlResultTag(outputEntity)
|
|
|
if err != nil {
|
|
@@ -74,7 +87,11 @@ func ParseSqlResult(input any, output any) error {
|
|
|
}
|
|
|
|
|
|
|
|
|
- outputEntities = reflect.Append(outputEntities, outputEntityValue.Elem())
|
|
|
+ if outputElemType.Kind() == reflect.Ptr {
|
|
|
+ outputEntities = reflect.Append(outputEntities, outputEntityValue)
|
|
|
+ } else {
|
|
|
+ outputEntities = reflect.Append(outputEntities, outputEntityValue)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -94,7 +111,6 @@ func ParseSqlResult(input any, output any) error {
|
|
|
}
|
|
|
|
|
|
func formOutputEntity(tableRow sdk.SqlResult, sqlResult *Result) error {
|
|
|
-
|
|
|
for fieldName, resultElement := range sqlResult.ResultElement {
|
|
|
switch element := resultElement.(type) {
|
|
|
case *Result:
|