-
Notifications
You must be signed in to change notification settings - Fork 141
Open
Description
- I've validated the bug against the latest version
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()andsyncMode: '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__whereandsubset__order_byparameters 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
Metadata
Metadata
Assignees
Labels
No labels