Describe the bug
When using columnMapper: snakeCamelMapper() in shapeOptions, column names in subset queries (used by on-demand and progressive sync modes) are sent to the server in camelCase instead of being converted to snake_case.
This affects:
- WHERE clauses - e.g.,
subset__where: "workflowId" = $1
- ORDER BY clauses - e.g.,
subset__order_by: "createdAt" DESC
- Function arguments - e.g.,
upper("firstName")
This causes queries to fail because the database columns are snake_case.
To Reproduce
- Create a collection with
columnMapper: snakeCamelMapper() and syncMode: 'on-demand' or 'progressive'
- Query the collection with a filter or ordering on a camelCase property (e.g.,
workflowId, createdAt)
- Observe the network request - the
subset__where and subset__order_by parameters contain camelCase column names instead of snake_case
Root cause
In packages/electric-db-collection/src/sql-compiler.ts:
function quoteIdentifier(name: string): string {
return `"${name}"` // Quotes camelCase directly without encoding
}
// Used here:
case `ref`:
return quoteIdentifier(exp.path[0]!) // e.g., returns "workflowId" not "workflow_id"
The compileSQL function doesn't have access to the columnMapper, so it can't encode column names before quoting them.
Electric's encodeWhereClause does get called on the compiled SQL, but it intentionally preserves double-quoted identifiers (correct PostgreSQL semantics), so the camelCase names pass through unchanged.
Additional context
- Electric client version: 1.3.0
- TanStack DB version: latest
Describe the bug
When using
columnMapper: snakeCamelMapper()inshapeOptions, column names in subset queries (used byon-demandandprogressivesync modes) are sent to the server in camelCase instead of being converted to snake_case.This affects:
subset__where: "workflowId" = $1subset__order_by: "createdAt" DESCupper("firstName")This causes queries to fail because the database columns are snake_case.
To Reproduce
columnMapper: snakeCamelMapper()andsyncMode: 'on-demand'or'progressive'workflowId,createdAt)subset__whereandsubset__order_byparameters contain camelCase column names instead of snake_caseRoot cause
In
packages/electric-db-collection/src/sql-compiler.ts:The
compileSQLfunction doesn't have access to thecolumnMapper, so it can't encode column names before quoting them.Electric's
encodeWhereClausedoes get called on the compiled SQL, but it intentionally preserves double-quoted identifiers (correct PostgreSQL semantics), so the camelCase names pass through unchanged.Additional context