-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[bun:sqlite] configurable javascript runtime type for sqlite integers #1536
Comments
The bug is here bun/src/bun.js/bindings/sqlite/JSSQLStatement.cpp Line 1045 in a251669
Bun should be getting as int64 instead |
It will now truncate up to 52 bits of precision (max int for a double) An improvement but not a complete fix ce6fc86 |
That's a great improvement @Jarred-Sumner, thanks!! |
As for whether to stop at double, or continue to the next level (BigInt, right?), I propose making it be an option like the example in the OP. Rationale: An option enables the choice based on user's requirements to tradeoff:
Thoughts? |
Yeah I think it should be an option that defaults to double We could copy better-sqlite3's api for this so that if people have existing apps using it, it's easier to switch |
Had to lookup better-sqlite3 :) That's great they had already thought of this and looks mostly good. I have one minor criticism that it conflates the use of BigInt with additional range checking and throwing on insert for "safety"; And that does not align with my approach to application development: I would tend to write the code that is already using domains/ranges as appropriate for the application and the application does its own checks when and if needed; And thus the extra checks in better-sqlite3 would be a slight bit of wasted overhead. But this is so minor that I wouldn't block it if other thinking about it still considers it essential for some reason, and that aside it looks good. |
As I was working on tursodatabase/libsql-client-ts#71, I wasn't able to return a Here's an API suggestion : const intType: "auto" | "bigint" | "number" | "string" = "auto"
db.setIntegerResultType(intType) //global
statement.setIntegerResultType(intType) //local Auto would automatically choose between For the query type we could use something similar similar |
What is the problem this feature would solve?
I'd like to propose an option for the sqlite API to go beyond the current 32-bit limit that is currently imposed on SELECT queries.
Background: Current API truncates integers to 32-bits when selecting (see below). Can be worked around by CASTing to REAL or TEXT (see below). Proposal objective: eliminate the
CAST()
.A common use case (for me): storage of epoch time values in milliseconds, which requires ~41-bits. The intended benefit of this proposal is that it would eliminate the need make query or schema alterations, helping to decouple runtime details of this API from sqlite.
What is the feature you are proposing to solve the problem?
An additional option is proposed to control integer conversion, perhaps as follows,
Number.MAX_SAFE_INTEGER
/Number.MIN_SAFE_INTEGER
)Examples of the concept:
Relevant lines ultimately impacted by this option are found in
constructResultObject()
andconstructResultRow()
:bun/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
Lines 994 to 997 in a251669
bun/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
Lines 1044 to 1047 in a251669
What alternatives have you considered?
Workarounds are possible:
REAL
typed columns in the schema. Or,CAST()
toREAL
. Or,CAST()
toTEXT
. And convert result to a BigInt in application code. (If up to the 64-bits is actually needed.)The text was updated successfully, but these errors were encountered: