From c1b016ea66d6dff5bafc1fa9a2a95b42fb29d078 Mon Sep 17 00:00:00 2001 From: Xin Hao Date: Wed, 24 Jan 2024 00:21:15 +0800 Subject: [PATCH 1/3] docs: add minimal example in the readme --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/README.md b/README.md index b6022959..aaf9881f 100644 --- a/README.md +++ b/README.md @@ -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) From e9c0a643bc1d8058d4a72e453d3e2a0e9ddc56d1 Mon Sep 17 00:00:00 2001 From: Xin Hao Date: Wed, 24 Jan 2024 00:23:30 +0800 Subject: [PATCH 2/3] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aaf9881f..ea92fa1a 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ For 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` +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: From 6a5bc536729abc21e6797a5358745df7e9f1bdef Mon Sep 17 00:00:00 2001 From: Xin Hao Date: Wed, 24 Jan 2024 00:25:04 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea92fa1a..aa7d17f7 100644 --- a/README.md +++ b/README.md @@ -89,10 +89,10 @@ func main() { 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 -` + $^.person.name AS name, + $^.person.age AS age, + like.likeness AS likeness` + resultSet, err := sessionPool.Execute(query) if err != nil { panic(err)