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

[BUG]: sqlite transactions can't be async for 4 of 5 implementations #2275

Open
DaAitch opened this issue May 8, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@DaAitch
Copy link

DaAitch commented May 8, 2024

What version of drizzle-orm are you using?

0.30.9

What version of drizzle-kit are you using?

0.20.17

Describe the Bug

The following async transaction doesn't work for any of the sqlite implementation (except sqlite-proxy)

await db.transaction(async tx => {
  await tx.delete(schema.items)

  if (items.length >= 1) {
    await tx.insert(schema.items)
      .values(items)
      .onConflictDoNothing()
  }
})

Logger will print something like this:

begin
delete from "items"
commit
insert into "items" values (...)

Expected behavior

Async transactions (like in the sqlite documentation)

await db.transaction(async tx => {
  await tx.delete(schema.items)

  if (items.length >= 1) {
    await tx.insert(schema.items)
      .values(items)
      .onConflictDoNothing()
  }
})

should work, like sync transactions

db.transaction(tx => {
  tx.delete(schema.items).run()

  if (items.length >= 1) {
    tx.insert(schema.items)
      .values(items)
      .onConflictDoNothing()
      .run()
  }
})

, but the transaction callbacks are not awaited, except for sqlite-proxy.

Environment & setup

  • expo-sqlite
  • better-sqlite3
  • bun-sqlite
  • op-sqlite
@DaAitch DaAitch added the bug Something isn't working label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant