Skip to content

Conversation

@ibarakaiev
Copy link

Summary

Fix encodeWhereClause to encode double-quoted identifiers. This addresses TanStack/db#927.

Problem

Query builders like @tanstack/electric-db-collection generate WHERE clauses (for subset__where) with double-quoted identifiers:

"userId" = $1 AND "createdAt" > $2

Quoting is a SQL best practice to handle reserved words and preserve case. However, encodeWhereClause was intentionally skipping quoted identifiers (line 258 tracks both ' and " as ranges to skip), presumably assuming that if you quoted it, you meant it literally.

This breaks columnMapper for any query builder that quotes identifiers - the column names never get transformed (e.g., userIduser_id).

Solution

Pre-process double-quoted identifiers before the existing logic runs:

whereClause = whereClause.replace(/"([^"]+)"/g, (_, identifier) => {
  return `"${encode(identifier)}"`
})

This should be safe because in PostgreSQL, double quotes are exclusively for identifiers (column/table names), never string literals (which use single quotes). So any "something" is a column name that should be encoded.

The rest of the function continues to handle unquoted identifiers and skip single-quoted string literals as before.

Query builders like @tanstack/electric-db-collection generate WHERE
clauses with double-quoted identifiers (e.g., "userId" = $1). These
need to be encoded by columnMapper just like unquoted identifiers.

In PostgreSQL, double quotes denote identifiers (column/table names),
not string literals (which use single quotes). So "userId" should be
transformed to "user_id" when using a snake_case columnMapper.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 17, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@electric-sql/react@3611
npm i https://pkg.pr.new/@electric-sql/client@3611
npm i https://pkg.pr.new/@electric-sql/y-electric@3611

commit: dc77a34

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.72%. Comparing base (73d18ec) to head (23b8090).
⚠️ Report is 8 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (73d18ec) and HEAD (23b8090). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (73d18ec) HEAD (23b8090)
unit-tests 4 3
typescript 4 3
packages/typescript-client 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3611       +/-   ##
===========================================
- Coverage   88.13%   72.72%   -15.41%     
===========================================
  Files          18        7       -11     
  Lines        1635      440     -1195     
  Branches      411      105      -306     
===========================================
- Hits         1441      320     -1121     
+ Misses        192      119       -73     
+ Partials        2        1        -1     
Flag Coverage Δ
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/typescript-client ?
packages/y-electric 55.66% <ø> (ø)
typescript 72.72% <ø> (-15.41%) ⬇️
unit-tests 72.72% <ø> (-15.41%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@netlify
Copy link

netlify bot commented Dec 17, 2025

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit dc77a34
🔍 Latest deploy log https://app.netlify.com/projects/electric-next/deploys/69431a0cfea9170008227b26
😎 Deploy Preview https://deploy-preview-3611--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@KyleAMathews
Copy link
Contributor

Closed in favor of #3629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants