Nebula Go¶
Nebula Go is a Golang client for connecting to and managing the Nebula Graph database.
Prerequisites¶
You have installed Golang 1.13 or later versions.
Compatibility with Nebula Graph¶
Nebula Graph version | Nebula Go version |
---|---|
2.5.1 | 2.5.0 |
2.0.1 | 2.0.0-GA |
2.0.0 | 2.0.0-GA |
Download Nebula Go¶
-
(Recommended) To install a specific version of Nebula Go, use the Git option
--branch
to specify the branch. For example, to install v2.5.0, run the following command:$ git clone --branch v2.5.0 https://github.com/vesoft-inc/nebula-go.git
-
To install the daily development version, run the following command to download the source code from the
master
branch:$ git clone https://github.com/vesoft-inc/nebula-go.git
Install or update¶
Run the following command to install or update Nebula Go:
$ go get -u -v github.com/vesoft-inc/nebula-go@<tag>
tag
: Specify the branch, such as master
or v2.5.0
.
Core of the example code¶
This section shows the core of the example code. For all the code, see graph_client_basic_example and graph_client_goroutines_example.
const (
address = "192.168.xx.1"
port = 9669
username = "root"
password = "nebula"
)
func main() {
hostAddress := nebula.HostAddress{Host: address, Port: port}
hostList := []nebula.HostAddress{hostAddress}
testPoolConfig := nebula.GetDefaultConf()
pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, log)
defer pool.Close()
session, err := pool.GetSession(username, password)
defer session.Release()
checkResultSet := func(prefix string, res *nebula.ResultSet) {
if !res.IsSucceed() {
log.Fatal(fmt.Sprintf("%s, ErrorCode: %v, ErrorMsg: %s", prefix, res.GetErrorCode(), res.GetErrorMsg()))
}
}
{
createSchema := "CREATE SPACE IF NOT EXISTS basic_example_space(vid_type=FIXED_STRING(20)); " +
"USE basic_example_space;" +
"CREATE TAG IF NOT EXISTS person(name string, age int);" +
"CREATE EDGE IF NOT EXISTS like(likeness double)"
resultSet, err := session.Execute(createSchema)
checkResultSet(createSchema, resultSet)
}
fmt.Print("\n")
log.Info("Nebula Go Client Basic Example Finished")
}
Last update: September 1, 2021