Skip to content

Commit

Permalink
support struct ptr in the slice
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxins committed Jun 30, 2024
1 parent cb38457 commit 33f24f7
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,9 @@ func (res ResultSet) scanRow(row *nebula.Row, colNames []string, rowType reflect
}

func scanListCol(vals []*nebula.Value, listVal reflect.Value, sliceType reflect.Type) error {
var listCol = reflect.MakeSlice(sliceType, 0, len(vals))

switch sliceType.Elem().Kind() {
case reflect.Struct:
var listCol = reflect.MakeSlice(sliceType, 0, len(vals))
for _, val := range vals {
ele := reflect.New(sliceType.Elem()).Elem()
err := scanStructField(val, ele, sliceType.Elem())
Expand All @@ -386,12 +385,23 @@ func scanListCol(vals []*nebula.Value, listVal reflect.Value, sliceType reflect.
}
listCol = reflect.Append(listCol, ele)
}
listVal.Set(listCol)
case reflect.Ptr:
var listCol = reflect.MakeSlice(sliceType, 0, len(vals))
for _, val := range vals {
ele := reflect.New(sliceType.Elem().Elem())
fmt.Println("debug ele", ele, "ele2", reflect.Indirect(ele))
err := scanStructField(val, reflect.Indirect(ele), sliceType.Elem())
if err != nil {
return err
}
listCol = reflect.Append(listCol, ele)
}
listVal.Set(listCol)
default:
return errors.New("scan: not support list type")
}

listVal.Set(listCol)

return nil
}

Expand Down Expand Up @@ -428,7 +438,7 @@ func scanStructField(val *nebula.Value, eleVal reflect.Value, eleType reflect.Ty
return nil
}

return errors.New("scan: not support struct type")
return nil
}

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

0 comments on commit 33f24f7

Please sign in to comment.