@@ -71,24 +71,25 @@ Example
71
71
72
72
.. code-block :: python
73
73
74
- from neo4j.v1 import GraphDatabase
74
+ from neo4j.v1 import GraphDatabase, basic_auth
75
75
76
- driver = GraphDatabase.driver(" bolt://localhost:7687" )
77
- session = driver.session()
76
+ driver = GraphDatabase.driver(" bolt://localhost:7687" , auth = basic_auth(" neo4j" , " password" ))
78
77
79
- session.run( " MERGE (a:Person {name:'Alice'}) " )
78
+ with driver.session() as session:
80
79
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'})" )
87
82
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})
90
88
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()
92
93
93
94
94
95
Indices and tables
0 commit comments