Skip to content

Commit

Permalink
safe bigints for better-sqlite3 changeset pulling
Browse files Browse the repository at this point in the history
better-sqlite3 is garbage at handling bigints. It truncates integers without warning if they are > 2^53. You can change the behavior to treat all integers as bigints but this is problematic too since not all ints are bigints.

Anyway... enable this behavior for the `changes` statements where all numbers can be 2^64.
  • Loading branch information
tantaman committed Jul 12, 2023
1 parent 05d7b7a commit 5c56d0f
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions js/packages/direct-connect-nodejs/src/private/DB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class DB {
`SELECT "table", "pk", "cid", "val", "col_version", "db_version" FROM crsql_changes WHERE db_version > ? AND site_id IS NOT ?`
);
this.#pullChangesetStmt.raw(true);
this.#pullChangesetStmt.safeIntegers(true);
const applyChangesetStmt = this.db.prepare(
`INSERT INTO crsql_changes ("table", "pk", "cid", "val", "col_version", "db_version", "site_id") VALUES (?, ?, ?, ?, ?, ?, ?)`
);
Expand Down

0 comments on commit 5c56d0f

Please sign in to comment.