Skip to content
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

feat(DAL): client-side support for JSON type #633

Merged

Conversation

kevin-dp
Copy link
Contributor

@kevin-dp kevin-dp commented Nov 7, 2023

This PR adds client-side support for the JSON type.
The DAL accepts JS values representing JSON and serialises them to a string that is stored in SQLite.
When reading a JSON value from the database the string is deserialised back into a JS value.
A corner case arises when having an optional column of type JSON because we need to differentiate between the database NULL value and the JSON null value. We treat the regular JS null value as a database NULL (to be consistent with how null values are interpreted for other column types) and require users to pass a special JsonNull object in order to store a top-level JSON null value.

Still need to add an E2E test for json values.

Copy link

linear bot commented Nov 7, 2023

VAX-863 DAL: add support for json type

Reference: https://electric-sql.slab.com/posts/on-data-validation-and-postgres-data-type-support-tpegouhj#h1sz5-supporting-basic-postgres-types-in-electric

  • Parse json from SQLite to JavaScript objects
  • Add client-side validations to ensure only valid JSON/JSON5 can be written to SQLite
  • Add a generative test that verifies correct validation of JSON values on the client (i.e. a value written on the client is guaranteed to also be written into the corresponding Postgres column)

@kevin-dp kevin-dp force-pushed the kevindp/vax-863-json-support branch 3 times, most recently from fb8581e to bd1b8cc Compare November 7, 2023 14:29
@alco alco force-pushed the kevindp/vax-863-json-support branch from f2a86a1 to c1d63d4 Compare November 13, 2023 22:50
@alco alco changed the base branch from alco/json to alco/vax-825-add-support-for-jsonb November 13, 2023 22:50
@kevin-dp kevin-dp merged commit b1a30e0 into alco/vax-825-add-support-for-jsonb Nov 29, 2023
11 checks passed
@kevin-dp kevin-dp deleted the kevindp/vax-863-json-support branch November 29, 2023 10:08
alco added a commit that referenced this pull request Nov 29, 2023
This PR adds client-side support for the JSON type.
The DAL accepts JS values representing JSON and serialises them to a
string that is stored in SQLite.
When reading a JSON value from the database the string is deserialised
back into a JS value.
A corner case arises when having an optional column of type JSON because
we need to differentiate between the database NULL value and the JSON
null value. We treat the regular JS null value as a database NULL (to be
consistent with how null values are interpreted for other column types)
and require users to pass a special JsonNull object in order to store a
top-level JSON null value.

Still need to add an E2E test for json values.

---------

Co-authored-by: Oleksii Sholik <[email protected]>
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