MCPcopy Index your code
hub / github.com/TanStack/db / runEagerSync

Function runEagerSync

packages/powersync-db-collection/src/powersync.ts:468–506  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

466 // Eager mode.
467 // Registers a diff trigger for the entire table.
468 function runEagerSync() {
469 let onUnload: CleanupFn | void | null = null
470
471 start(async () => {
472 onUnload = await restConfig.onLoad?.()
473
474 disposeTracking = await createDiffTrigger({
475 when: {
476 [DiffTriggerOperation.INSERT]: `TRUE`,
477 [DiffTriggerOperation.UPDATE]: `TRUE`,
478 [DiffTriggerOperation.DELETE]: `TRUE`,
479 },
480 writeType: (_rowId: string) => `insert`,
481 batchQuery: (
482 lockContext: LockContext,
483 batchSize: number,
484 cursor: number,
485 ) =>
486 lockContext.getAll<TableType>(
487 sanitizeSQL`SELECT * FROM ${viewName} LIMIT ? OFFSET ?`,
488 [batchSize, cursor],
489 ),
490 onReady: () => markReady(),
491 })
492 }).catch((error) =>
493 database.logger.error(
494 `Could not start syncing process for ${viewName} into ${trackedTableName}`,
495 error,
496 ),
497 )
498
499 return () => {
500 database.logger.info(
501 `Sync has been stopped for ${viewName} into ${trackedTableName}`,
502 )
503 abortController.abort()
504 onUnload?.()
505 }
506 }
507
508 // On-demand mode.
509 // Registers a diff trigger for the active WHERE expressions.

Callers 1

Calls 3

createDiffTriggerFunction · 0.85
getAllMethod · 0.80
startFunction · 0.70

Tested by

no test coverage detected