Skip to content

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.

@changeset-bot
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
@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
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