Skip to content

Commit

Permalink
Merge pull request #283 from tursodatabase/update-transaction-example
Browse files Browse the repository at this point in the history
Update transaction example
  • Loading branch information
giovannibenussi authored Oct 29, 2024
2 parents e1825ab + 0ce0806 commit 1608674
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions examples/transactions/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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");
Expand Down

0 comments on commit 1608674

Please sign in to comment.