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

Function extractCollectionFromSource

packages/db/src/query/live/utils.ts:108–127  ·  view source on GitHub ↗
(
  query: any,
)

Source from the content-addressed store, hash-verified

106 * The FROM clause may refer directly to a collection or indirectly to a subquery.
107 */
108export function extractCollectionFromSource(
109 query: any,
110): Collection<any, any, any> {
111 const from = query.from
112
113 if (from.type === `collectionRef`) {
114 return from.collection
115 } else if (from.type === `queryRef`) {
116 // Recursively extract from subquery
117 return extractCollectionFromSource(from.query)
118 } else if (from.type === `unionFrom`) {
119 return extractCollectionFromSource({ from: from.sources[0] })
120 } else if (from.type === `unionAll`) {
121 return extractCollectionFromSource(from.queries[0])
122 }
123
124 throw new Error(
125 `Failed to extract collection. Invalid FROM clause: ${JSON.stringify(query)}`,
126 )
127}
128
129/**
130 * Extracts all aliases used for each collection across the entire query tree.

Callers 1

constructorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected