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

Function processJoinResults

packages/db/src/query/compiler/joins.ts:588–650  ·  view source on GitHub ↗

* Processes the results of a join operation

(joinType: string)

Source from the content-addressed store, hash-verified

586 * Processes the results of a join operation
587 */
588function processJoinResults(joinType: string) {
589 return function (
590 pipeline: IStreamBuilder<
591 [
592 key: string,
593 [
594 [string, NamespacedRow] | undefined,
595 [string, NamespacedRow] | undefined,
596 ],
597 ]
598 >,
599 ): NamespacedAndKeyedStream {
600 return pipeline.pipe(
601 // Process the join result and handle nulls
602 filter((result) => {
603 const [_key, [main, joined]] = result
604 const mainNamespacedRow = main?.[1]
605 const joinedNamespacedRow = joined?.[1]
606
607 // Handle different join types
608 if (joinType === `inner`) {
609 return !!(mainNamespacedRow && joinedNamespacedRow)
610 }
611
612 if (joinType === `left`) {
613 return !!mainNamespacedRow
614 }
615
616 if (joinType === `right`) {
617 return !!joinedNamespacedRow
618 }
619
620 // For full joins, always include
621 return true
622 }),
623 map((result) => {
624 const [_key, [main, joined]] = result
625 const mainKey = main?.[0]
626 const mainNamespacedRow = main?.[1]
627 const joinedKey = joined?.[0]
628 const joinedNamespacedRow = joined?.[1]
629
630 // Merge the namespaced rows
631 const mergedNamespacedRow: NamespacedRow = {}
632
633 // Add main row data if it exists
634 if (mainNamespacedRow) {
635 Object.assign(mergedNamespacedRow, mainNamespacedRow)
636 }
637
638 // Add joined row data if it exists
639 if (joinedNamespacedRow) {
640 Object.assign(mergedNamespacedRow, joinedNamespacedRow)
641 }
642
643 // We create a composite key that combines the main and joined keys
644 const resultKey = `[${mainKey},${joinedKey}]`
645

Callers 1

processJoinFunction · 0.85

Calls 3

filterFunction · 0.90
mapFunction · 0.90
pipeMethod · 0.80

Tested by

no test coverage detected