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

Method mutate

packages/db/src/transactions.ts:296–317  ·  view source on GitHub ↗

* Execute collection operations within this transaction * @param callback - Synchronous function containing collection operations to group together. * The transaction context is active only for the synchronous duration of this callback. * Async work should happen in `mutationFn`; collection

(callback: () => void)

Source from the content-addressed store, hash-verified

294 * await tx.commit()
295 */
296 mutate(callback: () => void): Transaction<T> {
297 if (this.state !== `pending`) {
298 throw new TransactionNotPendingMutateError()
299 }
300
301 registerTransaction(this)
302
303 try {
304 callback()
305 } finally {
306 unregisterTransaction(this)
307 }
308
309 if (this.autoCommit) {
310 this.commit().catch(() => {
311 // Errors from autoCommit are handled via isPersisted.promise
312 // This catch prevents unhandled promise rejections
313 })
314 }
315
316 return this
317 }
318
319 /**
320 * Apply new mutations to this transaction, intelligently merging with existing mutations

Callers 15

persisted.test.tsFile · 0.45
powersync.test.tsFile · 0.45
createOptimisticActionFunction · 0.45
mutateFunction · 0.45
local-only.test.tsFile · 0.45
effect.test.tsFile · 0.45

Calls 3

commitMethod · 0.95
registerTransactionFunction · 0.85
unregisterTransactionFunction · 0.85

Tested by

no test coverage detected