Nebula GoGraph
Graph是一款Go语言的客户端,可以连接、管理NebulaGraph图数据库。
前提条件Graph
已安装Go,版本为1.13及以上。
版本对照表Graph
NebulaGraph版本 | Nebula Go版本 |
---|---|
2.6.0 | 2.6.0 |
2.0.1 | 2.0.0-GA |
2.0.0 | 2.0.0-GA |
下载Nebula GoGraph
-
(推荐)如果需要下载指定版本的Nebula Go,请使用选项
--branch
指定分支。例如安装v2.6.0发布版本,请执行如下命令:$ git clone --branch v2.6.0 https://github.com/vesoft-inc/nebula-go.git
-
如果需要安装日常开发版本,请执行如下命令下载
master
分支的源码:$ git clone https://github.com/vesoft-inc/nebula-go.git
安装或更新Graph
安装或更新的命令如下:
$ go get -u -v github.com/vesoft-inc/nebula-go@<tag>
tag
:指定分支。例如master
或v2.6.0
。
核心代码Graph
详细示例请参见Graph。
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")
}
最后更新: September 3, 2021