drizzle-orm
drizzle-orm copied to clipboard
[BUG]: sqlite transactions can't be async for 4 of 5 implementations
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 await
ed, except for sqlite-proxy.
- wrong: https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/expo-sqlite/session.ts#L69
- wrong: https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/better-sqlite3/session.ts#L83
- wrong: https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/bun-sqlite/session.ts#L93
- wrong: https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/op-sqlite/session.ts#L68
- good: https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/sqlite-proxy/session.ts#L85
Environment & setup
- expo-sqlite
- better-sqlite3
- bun-sqlite
- op-sqlite