sqlite3 icon indicating copy to clipboard operation
sqlite3 copied to clipboard

Support 64bit numbers

Open jackbow opened this issue 1 year ago • 3 comments

Or at least provide a warning somewhere I lost some time on this.

jackbow avatar Oct 08 '24 06:10 jackbow

Have you tried the int64 option? https://github.com/denodrivers/sqlite3/blob/main/doc.md#options

DjDeveloperr avatar Oct 09 '24 01:10 DjDeveloperr

Sorry about that! I had been switching between different drivers without looking at their individual options. Seems like the others must've had that on by default.

This actually makes me curious though - why not have int64 enabled by default?

jackbow avatar Oct 09 '24 19:10 jackbow

Previously it was slow to return bigints from Deno FFI but now it’s fast. But I’m still not sure what to do in this case: SQLite3 tells us there is a column value of int type, we don’t know if it’s 32 bit or 64 bit so we always assume 32 bit unless int64 option is specified, in which case a bigint is returned only when a value is too big to fit in JS number. So the value becomes a union number | bigint - which is not exactly ideal because bigints are not compatible with numbers and would need special handling like checking the type before it’s used with something. We have three options to default to:

  • return a 32 bit truncated value as JS number
  • always assume 64 bit and return a bigint
  • return number if value fits in 52 bits for JS number else bigint

Another option would be to maybe always get a 64 bit value and truncate it to 52 bits for JS number, which is certainly better than 32 bit and will support majority use cases. BigInts are not a performance issue in recent Deno FFI update anymore so it won’t have any negative impacts.

DjDeveloperr avatar Oct 09 '24 23:10 DjDeveloperr

I've added better documentation for this behavior and also now allow changing int64 at statement level. Closing this issue as completed for now.

DjDeveloperr avatar May 25 '25 22:05 DjDeveloperr