MCPcopy Create free account
hub / github.com/TanStack/db / rollback

Method rollback

packages/db/src/transactions.ts:410–435  ·  view source on GitHub ↗

* Rollback the transaction and any conflicting transactions * @param config - Configuration for rollback behavior * @returns This transaction for chaining * @example * // Manual rollback * const tx = createTransaction({ mutationFn: async () => { * // Send to API * }}) *

(config?: { isSecondaryRollback?: boolean })

Source from the content-addressed store, hash-verified

408 * }
409 */
410 rollback(config?: { isSecondaryRollback?: boolean }): Transaction<T> {
411 const isSecondaryRollback = config?.isSecondaryRollback ?? false
412 if (this.state === `completed`) {
413 throw new TransactionAlreadyCompletedRollbackError()
414 }
415
416 this.setState(`failed`)
417
418 // See if there's any other transactions w/ mutations on the same ids
419 // and roll them back as well.
420 if (!isSecondaryRollback) {
421 const mutationIds = new Set()
422 this.mutations.forEach((m) => mutationIds.add(m.globalKey))
423 for (const t of transactions) {
424 t.state === `pending` &&
425 t.mutations.some((m) => mutationIds.has(m.globalKey)) &&
426 t.rollback({ isSecondaryRollback: true })
427 }
428 }
429
430 // Reject the promise
431 this.isPersisted.reject(this.error?.error)
432 this.touchCollection()
433
434 return this
435 }
436
437 // Tell collection that something has changed with the transaction
438 touchCollection(): void {

Callers 3

commitMethod · 0.95
scheduler.test.tsFile · 0.45

Calls 5

setStateMethod · 0.95
touchCollectionMethod · 0.95
forEachMethod · 0.45
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected