From 0ce08068e2adfea3b10090b6c0053fee54ec7da3 Mon Sep 17 00:00:00 2001 From: Giovanni Date: Mon, 28 Oct 2024 22:23:33 -0300 Subject: [PATCH] Update transaction example --- examples/transactions/index.mjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/transactions/index.mjs b/examples/transactions/index.mjs index 98e0474..319ffa7 100644 --- a/examples/transactions/index.mjs +++ b/examples/transactions/index.mjs @@ -15,8 +15,9 @@ await client.batch( const names = ["John Doe", "Mary Smith", "Alice Jones", "Mark Taylor"]; +let transaction, secondTransaction; try { - const transaction = await client.transaction("write"); + transaction = await client.transaction("write"); for (const name of names) { await transaction.execute({ @@ -26,7 +27,7 @@ try { } await transaction.rollback(); - const secondTransaction = await client.transaction("write"); + secondTransaction = await client.transaction("write"); for (const name of names) { await secondTransaction.execute({ @@ -38,8 +39,8 @@ try { await secondTransaction.commit(); } catch (e) { console.error(e); - await transaction.rollback(); - await secondTransaction.rollback(); + await transaction?.rollback(); + await secondTransaction?.rollback(); } const result = await client.execute("SELECT * FROM users");