-
Notifications
You must be signed in to change notification settings - Fork 154
Fix sql-compiler to handle empty strings like eq(column, '')
#1146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+59
−4
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The sql-compiler was filtering out empty strings from query params, treating them the same as null/undefined values. This caused queries like `eq(column, '')` to incorrectly generate `WHERE column = NULL` instead of `WHERE column = ''`. The fix changes the filter condition to check the original value for null/undefined instead of checking if the serialized value is an empty string. This allows legitimate empty string queries to work correctly while still properly omitting null/undefined params.
🦋 Changeset detectedLatest commit: 12fb152 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: 0 B Total Size: 90.5 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.47 kB ℹ️ View Unchanged
|
Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
related #1146 |
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
thruflo
approved these changes
Jan 17, 2026
Contributor
|
🎉 This PR has been released! Thank you for your contribution! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes empty string values being incorrectly treated as NULL in SQL queries. Queries like
eq(status, '')now correctly generateWHERE status = ''instead of silently omitting the parameter.Reviewer Guidance
Root Cause
The sql-compiler's param filtering logic was checking if the serialized value was an empty string (
serialized !== '') to decide whether to include a param. This conflated two distinct cases:This caused legitimate empty string queries to break silently — the param would be omitted from the params record, but the
$Nplaceholder would still appear in the SQL, leading to incorrect query behavior.Approach
Changed the filter condition from checking the serialized output to checking the original input value:
Key Invariants
nullandundefinedparams MUST be omitted (they indicate optional/unset values)$Nplaceholders in the SQLNon-goals
IS NULLqueries (different feature)Trade-offs
Alternative considered: Could have made
serialize()returnnullfor null/undefined and then filter on that. Rejected because it would change the serialize function's contract and add complexity for a simple fix.Verification
The tests verify:
eqwith empty string includes the paramANDclause with empty string includes all paramshost_id = '')Files Changed
packages/electric-db-collection/src/sql-compiler.tspackages/electric-db-collection/tests/sql-compiler.test.tsFixes #1147