Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update transaction example #283

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading