【发布时间】:2022-11-11 02:31:56
【问题描述】:
从 Python 连接到正在运行的 Memgraph 实例需要什么?
【问题讨论】:
标签: memgraphdb
从 Python 连接到正在运行的 Memgraph 实例需要什么?
【问题讨论】:
标签: memgraphdb
要使用 Python 连接到 Memgraph,您需要:
创建一个新的 Python 脚本并向其中添加以下代码: 从 gqlalchemy 导入 Memgraph
# Make a connection to the database
memgraph = Memgraph(host='127.0.0.1', port=7687)
# Delete all nodes and relationships
query = "MATCH (n) DETACH DELETE n"
# Execute the query
memgraph.execute(query)
# Create a node with the label FirstNode and message property with the value "Hello, World!"
query = """CREATE (n:FirstNode)
SET n.message = '{message}'
RETURN 'Node ' + id(n) + ': ' + n.message AS result""".format(message="Hello, World!")
# Execute the query
results = memgraph.execute_and_fetch(query)
# Print the first member
print(list(results)[0]['result'])
您可以在Memgraph documentation 中找到详细说明。
【讨论】: