Skip to content

Commit 1608674

Browse files
Merge pull request #283 from tursodatabase/update-transaction-example
Update transaction example
2 parents e1825ab + 0ce0806 commit 1608674

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

examples/transactions/index.mjs

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ await client.batch(
1515

1616
const names = ["John Doe", "Mary Smith", "Alice Jones", "Mark Taylor"];
1717

18+
let transaction, secondTransaction;
1819
try {
19-
const transaction = await client.transaction("write");
20+
transaction = await client.transaction("write");
2021

2122
for (const name of names) {
2223
await transaction.execute({
@@ -26,7 +27,7 @@ try {
2627
}
2728
await transaction.rollback();
2829

29-
const secondTransaction = await client.transaction("write");
30+
secondTransaction = await client.transaction("write");
3031

3132
for (const name of names) {
3233
await secondTransaction.execute({
@@ -38,8 +39,8 @@ try {
3839
await secondTransaction.commit();
3940
} catch (e) {
4041
console.error(e);
41-
await transaction.rollback();
42-
await secondTransaction.rollback();
42+
await transaction?.rollback();
43+
await secondTransaction?.rollback();
4344
}
4445

4546
const result = await client.execute("SELECT * FROM users");

0 commit comments

Comments
 (0)