BEGIN ... COMMIT inserted wrong

I'm trying to run this code:

  await (db).transaction(async (tx: any) => {
    for (let i = 21; i <= 25; i++) {
      const r = await tx
        .insert(books)
        .values({ id: i, title: `tx ${i}`, price: i })
        .run()
    }
  })


And it prints the following line to console

BEGIN DEFERRED
insert into "books" ("id", "title", "price") values (21.0, 'tx 21', 21.0)
COMMIT
insert into "books" ("id", "title", "price") values (22.0, 'tx 22', 22.0)
insert into "books" ("id", "title", "price") values (23.0, 'tx 23', 23.0)
insert into "books" ("id", "title", "price") values (24.0, 'tx 24', 24.0)
insert into "books" ("id", "title", "price") values (25.0, 'tx 25', 25.0)


Why is this? Is it a serious bug with transactions (using better-sqlite3) or just a weirdness of the console log?

DB setup is as simple as


const sqlite = new BetterSQLite(dbPath, {
  verbose: console.log,
})
sqlite.pragma('journal_mode = WAL')

const db = drizzle({ client: sqlite })
Was this page helpful?