GraphDatabase_action

 

https://neo4j.com/docs/

#https://pypi.python.org/pypi/neo4j-driver/1.5.3
from neo4j.v1 import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("my@my.com","mypwd"))

def add_friends(tx, name, friend_name):
tx.run("MERGE (a:Person {name: $name}) "
"MERGE (a)-[:KNOWS]->(friend:Person {name: $friend_name})",
name=name, friend_name=friend_name)

def print_friends(tx, name):
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(friend) WHERE a.name = $name "
"RETURN friend.name ORDER BY friend.name", name=name):
print(record["friend.name"])

with driver.session() as session:
session.write_transaction(add_friends, "Arthur", "Guinevere")
session.write_transaction(add_friends, "Arthur", "Lancelot")
session.write_transaction(add_friends, "Arthur", "Merlin")
session.write_transaction(add_friends, "Arthur", "MyinputF")
session.read_transaction(print_friends, "Arthur")






Server version Neo4j/3.3.1
Server address 127.0.0.1:7687
Query MATCH (a:Person)-[:KNOWS]->(friend) WHERE a.name ="Arthur" RETURN friend.name ORDER BY friend.name
Response
[
  {
    "keys": [
      "friend.name"
    ],
    "length": 1,
    "_fields": [
      "Guinevere"
    ],
    "_fieldLookup": {
      "friend.name": 0
    }
  },
  {
    "keys": [
      "friend.name"
    ],
    "length": 1,
    "_fields": [
      "Lancelot"
    ],
    "_fieldLookup": {
      "friend.name": 0
    }
  },
  {
    "keys": [
      "friend.name"
    ],
    "length": 1,
    "_fields": [
      "Merlin"
    ],
    "_fieldLookup": {
      "friend.name": 0
    }
  },
  {
    "keys": [
      "friend.name"
    ],
    "length": 1,
    "_fields": [
      "Myinput"
    ],
    "_fieldLookup": {
      "friend.name": 0
    }
  },
  {
    "keys": [
      "friend.name"
    ],
    "length": 1,
    "_fields": [
      "MyinputF"
    ],
    "_fieldLookup": {
      "friend.name": 0
    }
  }
]
Started streaming 5 records after 1 ms and completed after 1 ms.
 
 
 
 

删除
 
Deleted 5687 nodes, deleted 4885 relationships, completed after 453 ms.





posted @ 2018-01-18 15:07  papering  阅读(614)  评论(0编辑  收藏  举报