Drivers

transaction

A unit of work that either succeeds in full or leaves no trace.

Also written: transactions

Example

Two writes in one unit of work.

python
def transfer_funds(tx, from_account, to_account, amount):
    # Deduct from first account
    tx.run(
        "MATCH (a:Account {id: $from_}) SET a.balance = a.balance - $amount",
        from_=from_account, amount=amount
    )
 
    # Add to second account
    tx.run(
        "MATCH (a:Account {id: $to}) SET a.balance = a.balance + $amount",
        to=to_account, amount=amount
    )

Both balances change together. If the second statement fails, neither of them does: the transaction rolls back, and the graph is as it was before the first.

Lessons that use this term

The lesson and course links below open in a new tab.

No published lesson uses this term yet.

All glossary terms