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

Function compileBasicExpression

packages/electric-db-collection/src/sql-compiler.ts:101–123  ·  view source on GitHub ↗

* Compiles the expression to a SQL string and mutates the params array with the values. * @param exp - The expression to compile * @param params - The params array * @param encodeColumnName - Optional function to encode column names (e.g., camelCase to snake_case) * @returns The compiled SQL str

(
  exp: IR.BasicExpression<unknown>,
  params: Array<unknown>,
  encodeColumnName?: ColumnEncoder,
)

Source from the content-addressed store, hash-verified

99 * @returns The compiled SQL string
100 */
101function compileBasicExpression(
102 exp: IR.BasicExpression<unknown>,
103 params: Array<unknown>,
104 encodeColumnName?: ColumnEncoder,
105): string {
106 switch (exp.type) {
107 case `val`:
108 params.push(exp.value)
109 return `$${params.length}`
110 case `ref`:
111 // TODO: doesn't yet support JSON(B) values which could be accessed with nested props
112 if (exp.path.length !== 1) {
113 throw new Error(
114 `Compiler can't handle nested properties: ${exp.path.join(`.`)}`,
115 )
116 }
117 return quoteIdentifier(exp.path[0]!, encodeColumnName)
118 case `func`:
119 return compileFunction(exp, params, encodeColumnName)
120 default:
121 throw new Error(`Unknown expression type`)
122 }
123}
124
125function compileOrderBy(
126 orderBy: IR.OrderBy,

Callers 3

compileSQLFunction · 0.85
compileOrderByClauseFunction · 0.85
compileFunctionFunction · 0.85

Calls 3

quoteIdentifierFunction · 0.70
compileFunctionFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected