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

Function parseOrderByExpression

packages/db/src/query/expression-helpers.ts:265–301  ·  view source on GitHub ↗
(
  orderBy: OrderBy | undefined | null,
)

Source from the content-addressed store, hash-verified

263 * ```
264 */
265export function parseOrderByExpression(
266 orderBy: OrderBy | undefined | null,
267): Array<ParsedOrderBy> {
268 if (!orderBy || orderBy.length === 0) {
269 return []
270 }
271
272 return orderBy.map((clause: IR.OrderByClause) => {
273 const field = extractFieldPath(clause.expression)
274
275 if (!field) {
276 throw new Error(
277 `ORDER BY expression must be a field reference, got: ${clause.expression.type}`,
278 )
279 }
280
281 const { direction, nulls } = clause.compareOptions
282 const result: ParsedOrderBy = {
283 field,
284 direction,
285 nulls,
286 }
287
288 // Add string collation options if present (discriminated union)
289 if (`stringSort` in clause.compareOptions) {
290 result.stringSort = clause.compareOptions.stringSort
291 }
292 if (`locale` in clause.compareOptions) {
293 result.locale = clause.compareOptions.locale
294 }
295 if (`localeOptions` in clause.compareOptions) {
296 result.localeOptions = clause.compareOptions.localeOptions
297 }
298
299 return result
300 })
301}
302
303/**
304 * Extracts all simple comparisons from a WHERE expression.

Callers 2

parseLoadSubsetOptionsFunction · 0.85

Calls 2

extractFieldPathFunction · 0.85
mapMethod · 0.45

Tested by

no test coverage detected