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

update branch of client #1469

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
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
25 changes: 4 additions & 21 deletions docs-2.0/14.client/3.nebula-cpp-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- (推荐)如果需要安装指定版本的 Nebula CPP,请使用选项`--branch`指定分支。例如安装 v{{ cpp.release }}发布版本,请执行如下命令:

```bash
$ git clone --branch v{{ cpp.release }} https://github.com/vesoft-inc/nebula-cpp.git
$ git clone --branch {{cpp.branch}} https://github.com/vesoft-inc/nebula-cpp.git
```

- 如果需要安装日常开发版本,请执行如下命令下载`master`分支的源码:
Expand Down Expand Up @@ -83,7 +83,7 @@

将 CPP 文件编译为可执行文件即可。接下来以`SessionExample.cpp`为例,介绍如何操作。

1. 使用[示例代码](https://github.com/vesoft-inc/nebula-cpp/blob/master/examples/SessionExample.cpp)创建`SessionExample.cpp`文件。
1. 使用[示例代码](https://github.com/vesoft-inc/nebula-cpp/blob/{{cpp.branch}}/examples/SessionExample.cpp)创建`SessionExample.cpp`文件。

2. 编译文件,命令如下:

Expand All @@ -103,22 +103,5 @@

### 核心代码

详细示例请参见 [SessionExample](https://github.com/vesoft-inc/nebula-cpp/blob/master/examples/SessionExample.cpp)。

```C++
nebula::init(&argc, &argv);
auto address = "192.168.xx.1:9669";
nebula::ConnectionPool pool;
pool.init({address}, nebula::Config{});
auto session = pool.getSession("root", "nebula");

auto result = session.execute("SHOW HOSTS");
std::cout << *result.data;

std::atomic_bool complete{false};
session.asyncExecute("SHOW HOSTS", [&complete](nebula::ExecutionResponse&& cbResult) {
std::cout << *cbResult.data;
complete.store(true);
});
session.release();
```
详细示例请参见 [SessionExample](https://github.com/vesoft-inc/nebula-cpp/blob/{{cpp.branch}}/examples/SessionExample.cpp)。

50 changes: 3 additions & 47 deletions docs-2.0/14.client/4.nebula-java-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- (推荐)如果需要使用指定版本的 Nebula Java,请使用选项`--branch`指定分支。例如使用 v{{ java.release }}发布版本,请执行如下命令:

```bash
$ git clone --branch v{{ java.release }} https://github.com/vesoft-inc/nebula-java.git
$ git clone --branch {{java.branch}} https://github.com/vesoft-inc/nebula-java.git
```

- 如果需要安装日常开发版本,请执行如下命令下载`master`分支的源码:
Expand Down Expand Up @@ -64,49 +64,5 @@

### 核心代码

详细示例请参见 [GraphClientExample](https://github.com/vesoft-inc/nebula-java/blob/master/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java)。

```java
NebulaPool pool = new NebulaPool();
Session session = null;
try {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(100);
List<HostAddress> addresses = Arrays.asList(new HostAddress("192.168.xx.1", 9669),
new HostAddress("192.168.xx.2", 9670));
pool.init(addresses, nebulaPoolConfig);
session = pool.getSession("root", "nebula", false);

//create space
String space = "test";
String createSpace = "CREATE SPACE IF NOT EXISTS " + space + " (partition_num=15, replica_factor=1, vid_type=fixed_string(30)); ";
ResultSet resp = session.execute(createSpace);

//create schema
String createSchema = "USE " + space + "; CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS like(likeness double)";
ResultSet resp = session.execute(createSchema);

//insert vertex
String insertVertexes = "INSERT VERTEX person(name, age) VALUES " + "'Bob':('Bob', 10), "
+ "'Lily':('Lily', 9), " + "'Tom':('Tom', 10), " + "'Jerry':('Jerry', 13), "
+ "'John':('John', 11);";
ResultSet resp = session.execute(insertVertexes);

// inert edge
String insertEdges = "INSERT EDGE like(likeness) VALUES " + "'Bob'->'Lily':(80.0), "
+ "'Bob'->'Tom':(70.0), " + "'Lily'->'Jerry':(84.0), " + "'Tom'->'Jerry':(68.3), "
+ "'Bob'->'John':(97.2);";
ResultSet resp = session.execute(insertEdges);

// query
String query = "GO FROM \"Bob\" OVER like " + "YIELD properties($$).name, properties($$).age, properties(edge).likeness";
ResultSet resp = session.execute(query);
printResult(resp);
}finally {
if (session != null) {
session.release();
}
pool.close();
}
```
详细示例请参见 [GraphClientExample](https://github.com/vesoft-inc/nebula-java/blob/{{java.branch}}/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java)。

67 changes: 3 additions & 64 deletions docs-2.0/14.client/5.nebula-python-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
### pip 安装

```bash
$ pip install nebula2-python==<version>
$ pip install nebula3-python==<version>
```

### 克隆源码安装
Expand All @@ -30,7 +30,7 @@ $ pip install nebula2-python==<version>
- (推荐)如果需要安装指定版本的 Nebula Python,请使用选项`--branch`指定分支。例如安装 v{{ python.release }}发布版本,请执行如下命令:

```bash
$ git clone --branch v{{ python.release }} https://github.com/vesoft-inc/nebula-python.git
$ git clone --branch {{python.branch}} https://github.com/vesoft-inc/nebula-python.git
```

- 如果需要安装日常开发版本,请执行如下命令下载`master`分支的源码:
Expand All @@ -53,66 +53,5 @@ $ pip install nebula2-python==<version>

## 核心代码

详细示例请参见 [Example](https://github.com/vesoft-inc/nebula-python/tree/master/example)。
详细示例请参见 [Example](https://github.com/vesoft-inc/nebula-python/tree/{{python.branch}}/example)。

### 连接 Graph 服务

```python
# 定义配置
config = Config()
config.max_connection_pool_size = 10
# 初始化连接池
connection_pool = ConnectionPool()
# 如果给定的服务器正常,则返回 true,否则返回 false。
ok = connection_pool.init([('192.168.xx.1', 9669)], config)

# 方法 1:控制连接自行释放。
# 从连接池中获取会话
session = connection_pool.get_session('root', 'nebula')

# 选择图空间
session.execute('USE basketballplayer')

# 执行查看 TAG 命令
result = session.execute('SHOW TAGS')
print(result)

# 释放会话
session.release()

# 方法 2:使用 session_context,会话将被自动释放。
with connection_pool.session_context('root', 'nebula') as session:
session.execute('USE basketballplayer;')
result = session.execute('SHOW TAGS;')
print(result)

# 关闭连接池
connection_pool.close()
```

### 连接 Storage 服务

```python
# 设置所有 Meta 服务地址
meta_cache = MetaCache([('192.168.xx.1', 9559),
('192.168.xx.2', 9559),
('192.168.xx.3', 9559)],
50000)
graph_storage_client = GraphStorageClient(meta_cache)

resp = graph_storage_client.scan_vertex(
space_name='ScanSpace',
tag_name='person')
while resp.has_next():
result = resp.next()
for vertex_data in result:
print(vertex_data)

resp = graph_storage_client.scan_edge(
space_name='ScanSpace',
edge_name='friend')
while resp.has_next():
result = resp.next()
for edge_data in result:
print(edge_data)
```
40 changes: 3 additions & 37 deletions docs-2.0/14.client/6.nebula-go-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- (推荐)如果需要下载指定版本的 Nebula Go,请使用选项`--branch`指定分支。例如安装 v{{ go.release }}发布版本,请执行如下命令:

```bash
$ git clone --branch v{{ go.release }} https://github.com/vesoft-inc/nebula-go.git
$ git clone --branch {{go.branch}} https://github.com/vesoft-inc/nebula-go.git
```

- 如果需要安装日常开发版本,请执行如下命令下载`master`分支的源码:
Expand All @@ -36,43 +36,9 @@
$ go get -u -v github.com/vesoft-inc/nebula-go@<tag>
```

`tag`:指定分支。例如`master`或`v{{ go.release }}`。
`tag`:指定分支。例如`master`或`{{go.branch}}`。

## 核心代码

详细示例请参见 [graph_client_basic_example](https://github.com/vesoft-inc/nebula-go/blob/master/basic_example/graph_client_basic_example.go) 和 [graph_client_goroutines_example](https://github.com/vesoft-inc/nebula-go/blob/master/gorountines_example/graph_client_goroutines_example.go)。
详细示例请参见 [graph_client_basic_example](https://github.com/vesoft-inc/nebula-go/blob/{{go.branch}}/basic_example/graph_client_basic_example.go) 和 [graph_client_goroutines_example](https://github.com/vesoft-inc/nebula-go/blob/{{go.branch}}/gorountines_example/graph_client_goroutines_example.go)。

```bash
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")
}
```