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

node:sqlite: When not using the BigInt mode, INTEGER values are overzealously wrapped #28187

Closed
frou opened this issue Feb 19, 2025 · 0 comments · Fixed by #28193
Closed

node:sqlite: When not using the BigInt mode, INTEGER values are overzealously wrapped #28187

frou opened this issue Feb 19, 2025 · 0 comments · Fixed by #28193
Assignees
Labels
node compat node:sqlite Issues related to the `node:sqlite` module

Comments

@frou
Copy link

frou commented Feb 19, 2025

Version: Deno 2.2.0

The documentation for node:sqlite says:

When reading from the database, SQLite INTEGERs are mapped to JavaScript numbers by default. However, SQLite INTEGERs can store values larger than JavaScript numbers are capable of representing.

...which is fair enough. But when NOT using the BigInt mode, things seem to be breaking down far too soon, e.g. in:

import { DatabaseSync } from "node:sqlite"
const db = new DatabaseSync(":memory:")
db.prepare("SELECT unixepoch(), unixepoch() * 2").get()
/*
{
  "unixepoch()": 1740003367,
  "unixepoch() * 2": -814960562
}
*/

...the second number is wrong. But it should work because the correct answer is a lot less than Number.MAX_SAFE_INTEGER.

(I noticed this in real-world code that multiplies the Unix Timestamp by 1000 so that it's in milliseconds instead of seconds)

@bartlomieju bartlomieju added node:sqlite Issues related to the `node:sqlite` module node compat labels Feb 19, 2025
littledivy added a commit to littledivy/deno that referenced this issue Feb 20, 2025
littledivy added a commit that referenced this issue Feb 20, 2025
Use `v8::Number` instead of `v8::Integer` to handle > i32::MAX.

Fixes #28187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
node compat node:sqlite Issues related to the `node:sqlite` module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants