denodrivers / sqlite3

The fastest and correct SQLite3 module for Deno runtime
https://jsr.io/@db/sqlite
Apache License 2.0
265 stars 22 forks source link

Support 64bit numbers #139

Open jackbow opened 1 month ago

jackbow commented 1 month ago

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

DjDeveloperr commented 1 month ago

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

jackbow commented 1 month ago

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?

DjDeveloperr commented 1 month ago

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:

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.