Skip to content

Commit

Permalink
Add more props
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxins committed Sep 19, 2024
1 parent b6d665c commit ada350f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,14 @@ func scanStructField(val *nebula.Value, eleVal reflect.Value, eleType reflect.Ty
edge := val.GetEVal()
if edge != nil {
props := edge.GetProps()

src := edge.GetSrc()
dst := edge.GetDst()
name := edge.GetName()
props["_src"] = src
props["_dst"] = dst
props["_name"] = &nebula.Value{SVal: name}

err := scanValFromProps(props, eleVal, eleType)
if err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions result_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,14 @@ func TestScanWithNestStruct(t *testing.T) {
}

type Person struct {
Vid string `nebula:"_vid"`
Name string `nebula:"name"`
City string `nebula:"city"`
}
type Friend struct {
Src string `nebula:"_src"`
Dst string `nebula:"_dst"`
EdgeName string `nebula:"_name"`
CreatedAt string `nebula:"created_at"`
}
type Result struct {
Expand All @@ -867,12 +871,16 @@ func TestScanWithNestStruct(t *testing.T) {
t.Error(err)
}
assert.Equal(t, 1, len(results))
assert.NotEmpty(t, results[0].Nodes[0].Vid)
assert.Equal(t, "Tom", results[0].Nodes[0].Name)
assert.Equal(t, "Shanghai", results[0].Nodes[0].City)
assert.Equal(t, "Bob", results[0].Nodes[1].Name)
assert.Equal(t, "Hangzhou", results[0].Nodes[1].City)
assert.Equal(t, "2024-07-07", results[0].Edges[0].CreatedAt)
assert.Equal(t, "2024-07-07", results[0].Edges[1].CreatedAt)
assert.NotEmpty(t, results[0].Edges[0].Src)
assert.NotEmpty(t, results[0].Edges[0].Dst)
assert.Equal(t, "friend", results[0].Edges[0].EdgeName)

// Scan again should work
err = resultSet.Scan(&results)
Expand Down

0 comments on commit ada350f

Please sign in to comment.