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

Method select

packages/db/src/query/builder/index.ts:578–601  ·  view source on GitHub ↗
(
    callback: (
      refs: RefsForContext<TContext>,
    ) => SelectObject | ScalarSelectValue,
  )

Source from the content-addressed store, hash-verified

576 callback: (refs: RefsForContext<TContext>) => TSelectValue,
577 ): QueryBuilder<WithResult<TContext, ResultTypeFromSelectValue<TSelectValue>>>
578 select(
579 callback: (
580 refs: RefsForContext<TContext>,
581 ) => SelectObject | ScalarSelectValue,
582 ) {
583 const aliases = this._getCurrentAliases()
584 const refProxy = createRefProxy(aliases) as RefsForContext<TContext>
585 let selectObject = callback(refProxy)
586
587 // Returning a top-level alias directly is equivalent to spreading it.
588 // Leaf refs like `row.name` must remain scalar selections.
589 if (isRefProxy(selectObject) && selectObject.__path.length === 1) {
590 const sentinelKey = `__SPREAD_SENTINEL__${selectObject.__path[0]}__0`
591 selectObject = { [sentinelKey]: true }
592 }
593
594 const select = buildNestedSelect(selectObject, aliases)
595
596 return new BaseQueryBuilder({
597 ...this.query,
598 select: select,
599 fnSelect: undefined, // remove the fnSelect clause if it exists
600 }) as any
601 }
602
603 /**
604 * Sort the query results by one or more columns

Calls 4

_getCurrentAliasesMethod · 0.95
createRefProxyFunction · 0.85
isRefProxyFunction · 0.85
buildNestedSelectFunction · 0.85

Tested by 15

createBasicTestsFunction · 0.64
testJoinTypeFunction · 0.64
createJoinTestsFunction · 0.64
createSubqueryTestsFunction · 0.64
createJoinSubqueryTestsFunction · 0.64
createDistinctTestsFunction · 0.64
buildIncludesQueryFunction · 0.64
buildNestedQueryFunction · 0.64
buildToArrayQueryFunction · 0.64