Skip to content

Commit eb9441f

Browse files
authored
Merge pull request #79 from neo4j/1.0-tx-example-with
Updated examples to use try block
2 parents a98f16d + b34aa32 commit eb9441f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

examples/test_examples.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def test_transaction_commit(self):
176176
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
177177
session = driver.session()
178178
# tag::transaction-commit[]
179-
tx = session.begin_transaction()
180-
tx.run("CREATE (:Person {name: 'Guinevere'})")
181-
tx.commit()
179+
with session.begin_transaction() as tx:
180+
tx.run("CREATE (:Person {name: 'Guinevere'})")
181+
tx.success = True
182182
# end::transaction-commit[]
183183
result = session.run("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)")
184184
record = next(iter(result))
@@ -189,9 +189,9 @@ def test_transaction_rollback(self):
189189
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
190190
session = driver.session()
191191
# tag::transaction-rollback[]
192-
tx = session.begin_transaction()
193-
tx.run("CREATE (:Person {name: 'Merlin'})")
194-
tx.rollback()
192+
with session.begin_transaction() as tx:
193+
tx.run("CREATE (:Person {name: 'Merlin'})")
194+
tx.success = False
195195
# end::transaction-rollback[]
196196
result = session.run("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)")
197197
record = next(iter(result))

0 commit comments

Comments
 (0)