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(electric): Add support for the int8 column type #653

Merged
merged 6 commits into from
Nov 29, 2023

Commits on Nov 13, 2023

  1. Configuration menu
    Copy the full SHA
    3347192 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6c0ae0f View commit details
    Browse the repository at this point in the history
  3. add changeset

    alco committed Nov 13, 2023
    Configuration menu
    Copy the full SHA
    4fca4bd View commit details
    Browse the repository at this point in the history

Commits on Nov 28, 2023

  1. feat (client): client-side support for int8 (#665)

    This PR adds client-side support for int8 aka bigint.
    Supporting BigInts is tricky because of inconsistencies in the sqlite
    drivers.
    For example, better-sqlite3 requires BigInts to be explicitly enabled
    but then *all* integers are returned as BigInts because SQLite does not
    distinguish between them (they are all just 64bit integers). On the
    other hand, wa-sqlite returns a regular JS number if the integer fits,
    otherwise it returns a BigInt.
    
    To avoid these problems, we always cast BigInt to text when reading from
    the DB and then let the DAL turn it into a BigInt;
    i.e., when the Postgres type of a column "foo" is bigint, we read as
    follows: `SELECT cast(foo as TEXT) AS foo FROM table`. Similarly, we
    cast returned values: `INSERT INTO table VALUES (9223372036854775807)
    RETURNING cast(foo as TEXT) AS foo`.
    
    A similar problem occurs in the oplog triggers. These triggers insert an
    oplog entry for every insert/update/delete. This oplog entry contains
    the old and new rows as JSON objects. However, JSON does not support
    BigInts:
    ```sql
    sqlite> SELECT json_valid('{"a": 123n}');
    0
    ```
    We also can't write it as a regular number because when parsing the JSON
    it is read as a number and rounding errors occur:
    ```js
    js> JSON.parse('{"a": 9223372036854775807}')
    { a: 9223372036854776000 }
    ```
    
    Hence, the triggers also need to cast BigInts to text and the
    deserialisation function for oplog entries (`deserialiseRow`) needs to
    correctly deserialise them as BigInts (when the column type is
    int8/bigint).
    
    ---------
    
    Co-authored-by: David Martos <[email protected]>
    kevin-dp and davidmartos96 authored Nov 28, 2023
    Configuration menu
    Copy the full SHA
    f9f4b47 View commit details
    Browse the repository at this point in the history

Commits on Nov 29, 2023

  1. Configuration menu
    Copy the full SHA
    4f260bb View commit details
    Browse the repository at this point in the history
  2. Update changeset

    alco committed Nov 29, 2023
    Configuration menu
    Copy the full SHA
    10e7271 View commit details
    Browse the repository at this point in the history