Skip to content

Commit f7b74e4

Browse files
committed
Updated README and fixed references to new_transaction
1 parent f75d9c0 commit f7b74e4

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

README.rst

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ Example Usage
2525
.. code:: python
2626
2727
from neo4j.v1 import GraphDatabase, basic_auth
28-
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
29-
session = driver.session()
30-
session.run("CREATE (a:Person {name:'Bob'})")
31-
result = session.run("MATCH (a:Person) RETURN a.name AS name")
32-
for record in result:
33-
print(record["name"])
34-
session.close()
28+
29+
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "password"))
30+
31+
with driver.session() as session:
32+
33+
with session.begin_transaction() as write_tx:
34+
write_tx.run("CREATE (a:Person {name:{name},age:{age}})", name="Alice", age=33)
35+
write_tx.run("CREATE (a:Person {name:{name},age:{age}})", name="Bob", age=44)
36+
write_tx.success = True
37+
38+
with session.begin_transaction() as read_tx:
39+
result = read_tx.run("MATCH (a:Person) RETURN a.name AS name, a.age AS age")
40+
for record in result:
41+
print("%s is %d years old" % (record["name"], record["age"]))
42+
43+
driver.close()
3544
3645
3746
Command Line

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Example
7979
session.run("MERGE (a:Person {name:'Alice'})")
8080
8181
friends = ["Bob", "Carol", "Dave", "Eve", "Frank"]
82-
with session.new_transaction() as tx:
82+
with session.begin_transaction() as tx:
8383
for friend in friends:
8484
tx.run("MATCH (a:Person {name:'Alice'}) "
8585
"MERGE (a)-[:KNOWS]->(x:Person {name:{n}})", {"n": friend})

neo4j/v1/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class Transaction(object):
404404
block where the value of :attr:`.success` will determine whether
405405
the transaction is committed or rolled back on :meth:`.Transaction.close`::
406406
407-
with session.new_transaction() as tx:
407+
with session.begin_transaction() as tx:
408408
pass
409409
410410
"""

0 commit comments

Comments
 (0)