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

Function loadSubset

packages/powersync-db-collection/src/powersync.ts:524–590  ·  view source on GitHub ↗
(
          options?: LoadSubsetOptions,
        )

Source from the content-addressed store, hash-verified

522 const activeWhereExpressions: Array<LoadSubsetOptions['where']> = []
523
524 const loadSubset = async (
525 options?: LoadSubsetOptions,
526 ): Promise<void> => {
527 if (options) {
528 activeWhereExpressions.push(options.where)
529 onUnloadSubset = await restConfig.onLoadSubset?.(options)
530 }
531
532 if (activeWhereExpressions.length === 0) {
533 await database.writeLock(async (ctx) => {
534 await flushDiffRecordsWithContext(ctx)
535 await disposeTracking?.({ context: ctx })
536 })
537 return
538 }
539
540 const combinedWhere =
541 activeWhereExpressions.length === 1
542 ? activeWhereExpressions[0]
543 : or(
544 activeWhereExpressions[0],
545 activeWhereExpressions[1],
546 ...activeWhereExpressions.slice(2),
547 )
548
549 const compiledNewData = compileSQLite(
550 { where: combinedWhere },
551 { jsonColumn: 'NEW.data' },
552 )
553
554 const compiledOldData = compileSQLite(
555 { where: combinedWhere },
556 { jsonColumn: 'OLD.data' },
557 )
558
559 const compiledView = compileSQLite({ where: combinedWhere })
560
561 const newDataWhenClause = toInlinedWhereClause(compiledNewData)
562 const oldDataWhenClause = toInlinedWhereClause(compiledOldData)
563 const viewWhereClause = toInlinedWhereClause(compiledView)
564
565 await database.writeLock(async (ctx) => {
566 await flushDiffRecordsWithContext(ctx)
567 await disposeTracking?.({ context: ctx })
568
569 disposeTracking = await createDiffTrigger({
570 setupContext: ctx,
571 when: {
572 [DiffTriggerOperation.INSERT]: newDataWhenClause,
573 [DiffTriggerOperation.UPDATE]: `(${newDataWhenClause}) OR (${oldDataWhenClause})`,
574 [DiffTriggerOperation.DELETE]: oldDataWhenClause,
575 },
576 writeType: (rowId: string) =>
577 collection.has(rowId) ? `update` : `insert`,
578 batchQuery: (
579 lockContext: LockContext,
580 batchSize: number,
581 cursor: number,

Callers 2

unloadSubsetFunction · 0.70
runOnDemandSyncFunction · 0.70

Calls 7

orFunction · 0.90
compileSQLiteFunction · 0.90
toInlinedWhereClauseFunction · 0.85
createDiffTriggerFunction · 0.85
getAllMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected