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

Function extractCorrelation

packages/db/src/query/builder/index.ts:1345–1375  ·  view source on GitHub ↗

* Checks if two eq() arguments form a parent-child correlation. * Returns the parent and child PropRefs if found, undefined otherwise.

(
  argA: BasicExpression,
  argB: BasicExpression,
  parentAliases: Array<string>,
  childAliases: Array<string>,
)

Source from the content-addressed store, hash-verified

1343 * Returns the parent and child PropRefs if found, undefined otherwise.
1344 */
1345function extractCorrelation(
1346 argA: BasicExpression,
1347 argB: BasicExpression,
1348 parentAliases: Array<string>,
1349 childAliases: Array<string>,
1350): { parentRef: PropRef; childRef: PropRef } | undefined {
1351 if (argA.type === `ref` && argB.type === `ref`) {
1352 const aAlias = argA.path[0]
1353 const bAlias = argB.path[0]
1354
1355 if (
1356 aAlias &&
1357 bAlias &&
1358 parentAliases.includes(aAlias) &&
1359 childAliases.includes(bAlias)
1360 ) {
1361 return { parentRef: argA, childRef: argB }
1362 }
1363
1364 if (
1365 aAlias &&
1366 bAlias &&
1367 parentAliases.includes(bAlias) &&
1368 childAliases.includes(aAlias)
1369 ) {
1370 return { parentRef: argB, childRef: argA }
1371 }
1372 }
1373
1374 return undefined
1375}
1376
1377// Internal function to build a query from a callback
1378// used by liveQueryCollectionOptions.query

Callers 1

buildIncludesSubqueryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected