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

docs: add minimal example in the readme #307

Merged
merged 5 commits into from
Jan 31, 2024
Merged
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
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,56 @@ For example:

## Usage example

### Mininal example

Suppose you already initialized your space and defined the schema as:
1. Vertex `person` with properties `name: string`, `age: int`
2. Edge `like` with properties `likeness: double`

You can query the Nebula by the minimal example:

```go
package main

import (
nebula "github.com/vesoft-inc/nebula-go/v3"
)

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

func main() {
hostAddress := nebula.HostAddress{Host: "127.0.0.1", Port: 3699}

config, err := nebula.NewSessionPoolConf(
"user",
"password",
[]nebula.HostAddress{hostAddress},
"space_name",
)

sessionPool, err := nebula.NewSessionPool(*config, nebula.DefaultLogger{})

query := `GO FROM 'Bob' OVER like YIELD
$^.person.name AS name,
$^.person.age AS age,
like.likeness AS likeness`

resultSet, err := sessionPool.Execute(query)
if err != nil {
panic(err)
}

var personList []Person
resultSet.Scan(&personList)
}
```

### More examples

[Simple Code Example](https://github.com/vesoft-inc/nebula-go/tree/master/examples/basic_example/graph_client_basic_example.go)

[Code Example with Goroutines](https://github.com/vesoft-inc/nebula-go/tree/master/examples/goroutines_example/graph_client_goroutines_example.go)
Expand Down
Loading