Skip to content

Commit 686edf3

Browse files
committed
support struct ptr in the slice
1 parent cb38457 commit 686edf3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

result_set.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,9 @@ func (res ResultSet) scanRow(row *nebula.Row, colNames []string, rowType reflect
374374
}
375375

376376
func scanListCol(vals []*nebula.Value, listVal reflect.Value, sliceType reflect.Type) error {
377-
var listCol = reflect.MakeSlice(sliceType, 0, len(vals))
378-
379377
switch sliceType.Elem().Kind() {
380378
case reflect.Struct:
379+
var listCol = reflect.MakeSlice(sliceType, 0, len(vals))
381380
for _, val := range vals {
382381
ele := reflect.New(sliceType.Elem()).Elem()
383382
err := scanStructField(val, ele, sliceType.Elem())
@@ -386,12 +385,22 @@ func scanListCol(vals []*nebula.Value, listVal reflect.Value, sliceType reflect.
386385
}
387386
listCol = reflect.Append(listCol, ele)
388387
}
388+
listVal.Set(listCol)
389+
case reflect.Ptr:
390+
var listCol = reflect.MakeSlice(sliceType, 0, len(vals))
391+
for _, val := range vals {
392+
ele := reflect.New(sliceType.Elem().Elem())
393+
err := scanStructField(val, reflect.Indirect(ele), sliceType.Elem().Elem())
394+
if err != nil {
395+
return err
396+
}
397+
listCol = reflect.Append(listCol, ele)
398+
}
399+
listVal.Set(listCol)
389400
default:
390401
return errors.New("scan: not support list type")
391402
}
392403

393-
listVal.Set(listCol)
394-
395404
return nil
396405
}
397406

@@ -428,7 +437,7 @@ func scanStructField(val *nebula.Value, eleVal reflect.Value, eleType reflect.Ty
428437
return nil
429438
}
430439

431-
return errors.New("scan: not support struct type")
440+
return nil
432441
}
433442

434443
func scanValFromProps(props map[string]*nebula.Value, val reflect.Value, tpe reflect.Type) error {

0 commit comments

Comments
 (0)