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 float4 #671

Conversation

kevin-dp
Copy link
Contributor

This PR adds client-side support for float4.
Numbers provided by the user are rounded to the nearest float4 representation using Math.fround().
Similarly, when numbers are read from a float4 column in the DB they are rounded to the nearest float4 representation.
This would not strictly be necessary if all writes happen through the DAL but because of SQLite's dynamic typing, users can write larger/smaller numbers to float4 columns in which case we would read numbers that fall out of range.

Copy link

linear bot commented Nov 16, 2023

VAX-849 DAL: add support for float4 type

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

  • Add client-side validations to ensure only floats that fall into float4's range get written to SQLite. This can be achieved with the help of Math.fround() which returns +-Infinity if given a floating point that has a magnitude that's too large or +-0.0 if the magnitude is too small for a 32-bit floating point representation

@kevin-dp kevin-dp force-pushed the kevindp/vax-849-support-float4-dal branch from 4595e69 to 23ea16e Compare November 16, 2023 07:59
Copy link
Member

@alco alco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

clients/typescript/test/client/conversions/sqlite.test.ts Outdated Show resolved Hide resolved
@kevin-dp kevin-dp merged commit 27ff924 into alco/vax-846-add-support-for-float4 Nov 28, 2023
11 checks passed
@kevin-dp kevin-dp deleted the kevindp/vax-849-support-float4-dal branch November 28, 2023 09:20
alco pushed a commit that referenced this pull request Nov 29, 2023
This PR adds client-side support for float4.
Numbers provided by the user are rounded to the nearest float4
representation using `Math.fround()`.
Similarly, when numbers are read from a float4 column in the DB they are
rounded to the nearest float4 representation.
This would not strictly be necessary if all writes happen through the
DAL but because of SQLite's dynamic typing, users can write
larger/smaller numbers to float4 columns in which case we would read
numbers that fall out of range.
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