@@ -71,24 +71,25 @@ Example
7171
7272.. code-block :: python
7373
74- from neo4j.v1 import GraphDatabase
74+ from neo4j.v1 import GraphDatabase, basic_auth
7575
76- driver = GraphDatabase.driver(" bolt://localhost:7687" )
77- session = driver.session()
76+ driver = GraphDatabase.driver(" bolt://localhost:7687" , auth = basic_auth(" neo4j" , " password" ))
7877
79- session.run( " MERGE (a:Person {name:'Alice'}) " )
78+ with driver.session() as session:
8079
81- friends = [" Bob" , " Carol" , " Dave" , " Eve" , " Frank" ]
82- with session.begin_transaction() as tx:
83- for friend in friends:
84- tx.run(" MATCH (a:Person {name:'Alice'}) "
85- " MERGE (a)-[:KNOWS]->(x:Person {name: {n}} )" , {" n" : friend})
86- tx.success = True
80+ with session.begin_transaction() as tx:
81+ session.run(" MERGE (a:Person {name:'Alice'})" )
8782
88- for friend, in session.run(" MATCH (a:Person {name:'Alice'})-[:KNOWS]->(x) RETURN x" ):
89- print (' Alice says, "hello, %s "' % friend[" name" ])
83+ friends = [" Bob" , " Carol" , " Dave" , " Eve" , " Frank" ]
84+ with session.begin_transaction() as tx:
85+ for friend in friends:
86+ tx.run(" MATCH (a:Person {name:'Alice'}) "
87+ " MERGE (a)-[:KNOWS]->(x:Person {name: {n}} )" , {" n" : friend})
9088
91- session.close()
89+ for friend, in session.run(" MATCH (a:Person {name:'Alice'})-[:KNOWS]->(x) RETURN x" ):
90+ print (' Alice says, "hello, %s "' % friend[" name" ])
91+
92+ driver.close()
9293
9394
9495 Indices and tables
0 commit comments