Skip to content

Commit

Permalink
Add documentation for transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedgreen committed Dec 14, 2021
1 parent bba4b0f commit 3b491b1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ export class DB {
return new PreparedQuery<R, O, P>(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<V>(closure: () => V): V {
this._transactionDepth += 1;
this.query(`SAVEPOINT _deno_sqlite_sp_${this._transactionDepth}`);
Expand Down

0 comments on commit 3b491b1

Please sign in to comment.