Tankōbon / main/db/transaction / withTransaction
Function: withTransaction()
withTransaction<
T>(db,fn):T
Defined in: main/db/transaction.ts:15
Runs fn in a transaction: committed when it returns, rolled back (and the error rethrown) when it throws. Without one, SQLite commits every statement on its own, which is slow for a batch (an import of 2 000 books) and leaves a half-written state when a write fails midway.
Calls nest: inside a transaction already open on db (the import wrapping the repositories' own transactions), fn simply joins it, and only the outermost call commits or rolls back.
Type Parameters
T
T
Parameters
db
DatabaseSync
fn
() => T
Returns
T