Skip to content

Commit

Permalink
docs: add minimal example in the readme (#307)
Browse files Browse the repository at this point in the history
* docs: add minimal example in the readme

* Update README.md

* Update README.md

---------

Co-authored-by: Anqi <[email protected]>
  • Loading branch information
haoxins and Nicole00 authored Jan 31, 2024
1 parent d0307aa commit 5d9b457
Showing 1 changed file with 50 additions and 0 deletions.
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

0 comments on commit 5d9b457

Please sign in to comment.