python from py2neo import Graph, Node, Relationship graph = Graph("bolt://localhost:7687") tx = graph.begin() try: node1 = Node("Person", name="Alice") relationship = Relationship(node1, "FRIEND", Node("Person", name="Bob")) tx.create(node1) tx.create(relationship) tx.commit() except Exception as e: tx.rollback() print("Error:", e) python from py2neo import Graph graph = Graph("bolt://localhost:7687") result = graph.run("CALL algo.shortestPath.stream('Person', 'name', 'Alice', 'name', 'Bob', {weightProperty:'distance'}) " "YIELD nodeId, cost RETURN algo.getNodeById(nodeId).name AS name, cost") for record in result: print(record["name"], record["cost"]) python from py2neo import Graph graph = Graph("bolt://localhost:7687") graph.run("LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS row " "CREATE (:Person {name: row.name, age: row.age})") graph.run("MATCH (p:Person) " "RETURN p.name AS name, p.age AS age " "INTO CSV 'file:///data.csv'")


上一篇:
下一篇:
切换中文