Created
October 25, 2022 08:27
-
-
Save wfng92/9da988015e5889468924da325aa12946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nebula3.gclient.net import ConnectionPool | |
from nebula3.Config import Config | |
# define a config | |
config = Config() | |
config.max_connection_pool_size = 10 | |
# init connection pool | |
connection_pool = ConnectionPool() | |
# if the given servers are ok, return true, else return false | |
ok = connection_pool.init([('127.0.0.1', 9669)], config) | |
# initialize with session_context, session will be released automatically at the end | |
with connection_pool.session_context('root', 'root') as session: | |
session.execute('USE test') | |
# execute your custom query here | |
result = session.execute('FETCH PROP ON person "Bob" YIELD vertex as node') | |
# convert ResultSet to dict | |
columns = result.keys() | |
d = {} | |
for col_num in range(result.col_size()): | |
col_name = columns[col_num] | |
col_list = result.column_values(col_name) | |
d[col_name] = [x for x in col_list] | |
print(d) | |
# close the pool | |
connection_pool.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment