transactions-python
Installation
SKILL.md
Couchbase Transactions — Python
ACID multi-document transactions. All operations in a transaction commit atomically or roll back entirely.
Version requirement: Distributed transactions require Couchbase Server 7.0+. The 6.6 developer preview is not recommended for production.
Bank Transfer Example
from couchbase.exceptions import TransactionFailed, TransactionExpired, TransactionCommitAmbiguous
def transfer_funds(cluster, collection, from_id, to_id, amount):
def txn_logic(ctx):
sender = ctx.get(collection, from_id)
receiver = ctx.get(collection, to_id)
sender_doc = sender.content_as[dict]
receiver_doc = receiver.content_as[dict]