File size: 1,570 Bytes
0749826
 
 
 
7f18af8
 
 
ff1d723
 
0749826
 
 
 
 
ff1d723
0749826
 
 
2012a16
 
 
 
 
0749826
2012a16
 
 
 
 
 
 
 
c2bf5de
2012a16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import time
import subprocess


subprocess.call("curl -fsSL https://get.docker.com -o get-docker.sh", shell=True)
subprocess.call("sh get-docker.sh", shell=True)
subprocess.call("wget https://github.com/vesoft-inc/nebula/releases/download/v3.3.0/nebula-3.3.0-ubuntu-amd64.deb", shell=True)
subprocess.call("sudo dpkg -i nebula-3.3.0-ubuntu-amd64.deb", shell=True)
# Nebula Graphサービスの起動
subprocess.call("nebula-metad --daemon", shell=True)
subprocess.call("nebula-storaged --daemon", shell=True)
subprocess.call("nebula-graphd --daemon", shell=True)


# サービスが起動するまでの遅延
time.sleep(10)  # 10秒待機(必要に応じて調整)

from nebula3.Config import Config
from nebula3.gclient.net import ConnectionPool
from nebula3.mclient import MetaCache
from nebula3.gclient.net import Connection
from nebula3.graph import GraphService

# 接続設定
config = Config()
config.max_connection_pool_size = 10

# 接続プールの初期化
connection_pool = ConnectionPool()

# Nebula Graph に接続
if not connection_pool.init([('127.0.0.1', 9669)], config):
    print("接続に失敗しました")
    exit(1)

# セッションの取得
session = connection_pool.get_session('username', 'password')

# クエリの実行
result_set = session.execute('SHOW SPACES')

# 結果の表示
if not result_set.is_succeeded():
    print(result_set.error_msg())
else:
    for result in result_set.rows():
        print(result)

# セッションを閉じる
session.release()

# 接続プールを閉じる
connection_pool.close()