From 3b491b1ceda495f1bbc9069b2c44a5cbf2d80cec Mon Sep 17 00:00:00 2001 From: Tilman Roeder Date: Sat, 11 Dec 2021 14:35:29 +0000 Subject: [PATCH] Add documentation for transactions. --- src/db.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/db.ts b/src/db.ts index de97db5..032dfec 100644 --- a/src/db.ts +++ b/src/db.ts @@ -196,6 +196,15 @@ export class DB { return new PreparedQuery(this._wasm, stmt, this._statements); } + /** + * Run a function within the context of a database + * transaction. If the function throws an error, + * the transaction is rolled back. Otherwise, the + * transaction is committed when the function returns. + * + * Calls to `transaction` may be nested. Nested transactions + * behave like SQLite save points. + */ transaction(closure: () => V): V { this._transactionDepth += 1; this.query(`SAVEPOINT _deno_sqlite_sp_${this._transactionDepth}`);