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

D1: roll-back in batch command not working #484

Closed
anthonymclaughlin opened this issue Jan 29, 2023 · 1 comment
Closed

D1: roll-back in batch command not working #484

anthonymclaughlin opened this issue Jan 29, 2023 · 1 comment

Comments

@anthonymclaughlin
Copy link

From the docs:

Batched statements are SQL transactions. If a statement in the sequence fails, then an error is returned for that specific statement, and it aborts or rolls back the entire sequence.

When I have a couple of INSERT statements and the second one has a typo (a deliberate INSERTZ in the code example below), an error is thrown but the first statement still works.

code example:

const db = context.env.ACCOUNT_D1_TEST;

  await db.batch([
    db
      .prepare(
        `
        INSERT INTO account
        (id, date_created) 
        VALUES (?,?);
    `
      )
      .bind(newAccountId, now),
    db
      .prepare(
        `
        INSERTZ INTO account_user
        (id, date_created, account_id, credential_username, credential_password_hash, role_of_owner)
        VALUES (?1,?2,?3,?4,?5,?6);
    `
      )
      .bind(newAccountUserId, now, newAccountId, username, cipherText, 1),
  ]);

This is happening in the local development environment using the command: wrangler dev --local --persist

wrangler v2.8.1
node v16.19.0
sqlite v3.34.1

@mrbbot
Copy link
Contributor

mrbbot commented Feb 1, 2023

Hey! 👋 This should've been fixed by #480, and will be released soon. I'd like to include #486 in this, so just waiting until that's approved. 👍

@mrbbot mrbbot closed this as completed Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants