Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example code for using ResultSet Scan #303

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion examples/session_pool_example/session_pool_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ const (
// Initialize logger
var log = nebula.DefaultLogger{}

type Person struct {
Name string `nebula:"name"`
Age int `nebula:"age"`
Likeness float64 `nebula:"likeness"`
}

func main() {
prepareSpace()
hostAddress := nebula.HostAddress{Host: address, Port: port}
Expand Down Expand Up @@ -94,7 +100,7 @@ func main() {
}
// Extract data from the resultSet
{
query := "GO FROM 'Bob' OVER like YIELD $^.person.name, $^.person.age, like.likeness"
query := "GO FROM 'Bob' OVER like YIELD $^.person.name AS name, $^.person.age AS age, like.likeness AS likeness"
// Send query in goroutine
wg := sync.WaitGroup{}
wg.Add(1)
Expand All @@ -108,6 +114,10 @@ func main() {
return
}
checkResultSet(query, resultSet)
var personList []Person
resultSet.Scan(&personList)
fmt.Printf("personList: %v\n", personList)
// personList: [{Bob 10 97.2} {Bob 10 80} {Bob 10 70}]
}(&wg)
wg.Wait()

Expand Down
4 changes: 4 additions & 0 deletions result_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,12 @@ func (res ResultSet) scanRow(row *nebula.Row, colNames []string, t reflect.Type)
rowVal := rowVals[cIdx]

switch f.Type.Kind() {
case reflect.Int:
val.Field(fIdx).SetInt(rowVal.GetIVal())
case reflect.Int64:
val.Field(fIdx).SetInt(rowVal.GetIVal())
case reflect.Float64:
val.Field(fIdx).SetFloat(rowVal.GetFVal())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we need to process bool/float32/int8/int16/date/datetime/time/duration/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need, but I will open another PR to do this.
Also we need enhance/refactor the tests.
this is just make the example works.

case reflect.String:
val.Field(fIdx).SetString(string(rowVal.GetSVal()))
default:
Expand Down
Loading