Skip to content

columnMapper encoding not applied to column names in subset queries #1032

@marbemac

Description

@marbemac
  • 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

  1. Create a collection with columnMapper: snakeCamelMapper() and syncMode: 'on-demand' or 'progressive'
  2. Query the collection with a filter or ordering on a camelCase property (e.g., workflowId, createdAt)
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions