Skip to content

Commit 33f24f7

Browse files
committed
support struct ptr in the slice
1 parent cb38457 commit 33f24f7

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

result_set.go

Lines changed: 15 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,23 @@ 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+
fmt.Println("debug ele", ele, "ele2", reflect.Indirect(ele))
394+
err := scanStructField(val, reflect.Indirect(ele), sliceType.Elem())
395+
if err != nil {
396+
return err
397+
}
398+
listCol = reflect.Append(listCol, ele)
399+
}
400+
listVal.Set(listCol)
389401
default:
390402
return errors.New("scan: not support list type")
391403
}
392404

393-
listVal.Set(listCol)
394-
395405
return nil
396406
}
397407

@@ -428,7 +438,7 @@ func scanStructField(val *nebula.Value, eleVal reflect.Value, eleType reflect.Ty
428438
return nil
429439
}
430440

431-
return errors.New("scan: not support struct type")
441+
return nil
432442
}
433443

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

0 commit comments

Comments
 (0)