Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefano-ottolenghi committed Nov 17, 2023
1 parent 2f75560 commit 2674129
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions python-manual/modules/ROOT/pages/transactions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ You run queries inside an explicit transaction with the method link:{neo4j-docs-
----
with driver.session(database="neo4j") as session:
with session.begin_transaction() as tx:
...
# use tx.run() to run queries
tx.run("<QUERY 1>")
tx.run("<QUERY 2>")
----

Closing an explicit transaction can either happen automatically at the end of a `with` block, or can be explicitly controlled through the methods link:{neo4j-docs-base-uri}/api/python-driver/current/api.html#neo4j.Transaction.commit[`Transaction.commit()`], link:{neo4j-docs-base-uri}/api/python-driver/current/api.html#neo4j.Transaction.rollback[`Transaction.rollback()`], or link:{neo4j-docs-base-uri}/api/python-driver/current/api.html#neo4j.Transaction.close[`Transaction.close()`].
Expand All @@ -202,19 +203,20 @@ import neo4j
URI = "<URI for Neo4j database>"
AUTH = ("<Username>", "<Password>")
def main():
with neo4j.GraphDatabase.driver(URI, auth=AUTH) as driver:
customer_id = create_customer()
customer_id = create_customer(driver)
other_bank_id = 42
transfer_to_other_bank(driver, customer_id, other_bank_id, 999)
def create_customer():
def create_customer(driver):
result, _, _ = driver.execute_query("""
MERGE (c:Customer {id: rand()})
RETURN c.id
RETURN c.id AS id
""", database_ = "neo4j")
return result[0]["c.id"]
return result[0]["id"]
def transfer_to_other_bank(driver, customer_id, other_bank_id, amount):
Expand Down Expand Up @@ -251,8 +253,8 @@ def customer_balance_check(tx, customer_id, amount):
def other_bank_transfer_api(customer_id, other_bank_id, amount):
...
# make some API call to other bank
pass
def decrease_customer_balance(tx, customer_id, amount):
Expand Down

0 comments on commit 2674129

Please sign in to comment.