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

Function compileOrderByClause

packages/powersync-db-collection/src/sqlite-compiler.ts:135–156  ·  view source on GitHub ↗

* Compiles a single OrderByClause to SQL.

(
  clause: IR.OrderByClause,
  params: Array<unknown>,
  compileOptions?: CompileSQLiteOptions,
)

Source from the content-addressed store, hash-verified

133 * Compiles a single OrderByClause to SQL.
134 */
135function compileOrderByClause(
136 clause: IR.OrderByClause,
137 params: Array<unknown>,
138 compileOptions?: CompileSQLiteOptions,
139): string {
140 const { expression, compareOptions } = clause
141 let sql = compileExpression(expression, params, compileOptions)
142
143 if (compareOptions.direction === `desc`) {
144 sql = `${sql} DESC`
145 }
146
147 // SQLite supports NULLS FIRST/LAST (since 3.30.0)
148 if (compareOptions.nulls === `first`) {
149 sql = `${sql} NULLS FIRST`
150 } else {
151 // Default to NULLS LAST (nulls === 'last')
152 sql = `${sql} NULLS LAST`
153 }
154
155 return sql
156}
157
158/**
159 * Check if a BasicExpression represents a null/undefined value

Callers 1

compileOrderByFunction · 0.70

Calls 1

compileExpressionFunction · 0.70

Tested by

no test coverage detected