method

SavepointSQL.savepoint

name: string,
): Promise<ContextCallbackResult<T>>;

Creates a savepoint within the current transaction.

The callback gets a client of its own, which ends with the savepoint. savepoint resolves with the callback's return value. If the callback throws, Bun rolls back to the savepoint and savepoint rejects with the error: catch it to continue the transaction.

Run the savepoints of one transaction one after the other. A savepoint holds every statement that the connection runs while it is open, so a savepoint that fails also rolls back the work of one that runs next to it.

@param name

A label. Bun appends it to the name it generates, for example SAVEPOINT s0_audit for "audit". Each character that is not an ASCII letter, a digit or _ becomes _.

Referenced types

type SavepointContextCallback<T> = ContextCallback<T, SavepointSQL>

Callback function type for savepoint contexts

type ContextCallbackResult<T> = T extends PromiseLike<any>[] ? AwaitPromisesArray<T> : Awaited<T>