Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from nebula3.Config import Config
|
2 |
+
from nebula3.gclient.net import ConnectionPool
|
3 |
+
from nebula3.mclient import MetaCache
|
4 |
+
from nebula3.gclient.net import Connection
|
5 |
+
from nebula3.graph import GraphService
|
6 |
+
|
7 |
+
# 接続設定
|
8 |
+
config = Config()
|
9 |
+
config.max_connection_pool_size = 10
|
10 |
+
|
11 |
+
# 接続プールの初期化
|
12 |
+
connection_pool = ConnectionPool()
|
13 |
+
|
14 |
+
# Nebula Graph に接続
|
15 |
+
if not connection_pool.init([(‘127.0.0.1’, 9669)], config):
|
16 |
+
print("接続に失敗しました")
|
17 |
+
exit(1)
|
18 |
+
|
19 |
+
# セッションの取得
|
20 |
+
session = connection_pool.get_session('username', 'password')
|
21 |
+
|
22 |
+
# クエリの実行
|
23 |
+
result_set = session.execute('SHOW SPACES')
|
24 |
+
|
25 |
+
# 結果の表示
|
26 |
+
if not result_set.is_succeeded():
|
27 |
+
print(result_set.error_msg())
|
28 |
+
else:
|
29 |
+
for result in result_set.rows():
|
30 |
+
print(result)
|
31 |
+
|
32 |
+
# セッションを閉じる
|
33 |
+
session.release()
|
34 |
+
|
35 |
+
# 接続プールを閉じる
|
36 |
+
connection_pool.close()
|