Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix -> operator on missing values to return null #193

Merged
merged 7 commits into from
Feb 4, 2025
Merged

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Feb 4, 2025

Using the -> operator with a missing value, for example select '{}' -> 'test', would return undefined instead of null. We use SQLite types, so there should never be an undefined value.

This was specifically an issue when used together with json_each, for example SELECT value as project_id FROM json_each(request.jwt() -> 'project_ids'). This query would throw an error Expected json_each to be called with a string, got undefined, instead of treating it like an empty array like with null values.

This fixes select '{}' -> 'test' to return null correctly.

This also adds tests for all the following forms:

select '{"t": null}' -> 't' -- null in PowerSync, 'null' in SQLite
select '{}' -> 't' -- null in PowerSync and SQLite, fixed by this PR

select '{"t": null}' ->> 't' -- 'null' in PowerSync, null in SQLite
select '{}' ->> 't' -- null in PowerSync and SQLite

select json_extract('{"t": null}', '$.t') -- 'null' in PowerSync, null in SQLite
select json_extract('{}', '$.t') -- null in PowerSync and SQLite

Notice the difference in handling of {"t": null} values between PowerSync and SQLite. That is not affected by this PR though, and fixing it to match SQLite would be a breaking change, so keeping it as-is for now.

Copy link

changeset-bot bot commented Feb 4, 2025

🦋 Changeset detected

Latest commit: a332599

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@powersync/service-sync-rules Patch
@powersync/service-core-tests Patch
@powersync/service-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
@powersync/service-image Patch
test-client Patch

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

stevensJourney
stevensJourney previously approved these changes Feb 4, 2025
packages/sync-rules/src/sql_functions.ts Outdated Show resolved Hide resolved
@rkistner rkistner merged commit e26e434 into main Feb 4, 2025
15 checks passed
@rkistner rkistner deleted the fix-json-null branch February 4, 2025 13:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants