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

Function compileOrderByClause

packages/electric-db-collection/src/sql-compiler.ts:136–159  ·  view source on GitHub ↗
(
  clause: IR.OrderByClause,
  params: Array<unknown>,
  encodeColumnName?: ColumnEncoder,
)

Source from the content-addressed store, hash-verified

134}
135
136function compileOrderByClause(
137 clause: IR.OrderByClause,
138 params: Array<unknown>,
139 encodeColumnName?: ColumnEncoder,
140): string {
141 // FIXME: We should handle stringSort and locale.
142 // Correctly supporting them is tricky as it depends on Postgres' collation
143 const { expression, compareOptions } = clause
144 let sql = compileBasicExpression(expression, params, encodeColumnName)
145
146 if (compareOptions.direction === `desc`) {
147 sql = `${sql} DESC`
148 }
149
150 if (compareOptions.nulls === `first`) {
151 sql = `${sql} NULLS FIRST`
152 }
153
154 if (compareOptions.nulls === `last`) {
155 sql = `${sql} NULLS LAST`
156 }
157
158 return sql
159}
160
161/**
162 * Check if a BasicExpression represents a null/undefined value

Callers 1

compileOrderByFunction · 0.70

Calls 1

compileBasicExpressionFunction · 0.85

Tested by

no test coverage detected