Skip to content

feat: bind BigInt parameters as 64-bit integers - #648

Merged
lovasoa merged 1 commit into
sql-js:masterfrom
colinhacks:bind-bigint-int64
Nov 17, 2026
Merged

lovasoa merged 1 commit into
sql-js:masterfrom
colinhacks:bind-bigint-int64

Conversation

@colinhacks

Copy link
Copy Markdown
Contributor

A BigInt parameter is bound as its decimal text, so it's stored as TEXT and compares as text:

const db = new SQL.Database();
db.exec("SELECT typeof(?), ? = 42", [42n, 42n]);
// [{ columns: [...], values: [["text", 0]] }]

A query like WHERE id = ? with a BigInt id finds nothing, and INTEGER affinity is the only thing that turns an inserted value back into a number. A value outside the 64-bit range is stored as text too, with no error.

This binds a BigInt with sqlite3_bind_int64, and throws a RangeError for one outside the 64-bit range. The same query gives [["integer", 1]].

The WebAssembly builds pass the value to C as a BigInt. The asm.js builds can't (Emscripten turns off BigInt integration under -sWASM=0 and splits an i64 into two i32 halves), so there it's passed as its low and high 32 bits. Which ABI a build has is read once at startup from sqlite3_memory_used(), which returns an i64.

Tests in test/test_big_int.js cover small and negative values, values past Number.MAX_SAFE_INTEGER, both ends of the 64-bit range, both out-of-range sides, named parameters, and a WHERE match against a stored integer. CI on the fork passes, and test/all.js passes test big int on the three asm.js builds as well (issue482 and native_math_functions fail there on 1.16.0 already).

Closes #341

A BigInt was bound as its decimal text, so it was stored as TEXT and compared as text. Bind it with sqlite3_bind_int64 instead, and throw a RangeError for a BigInt outside the 64-bit range.
Copilot AI balanced review requested due to automatic review settings November 16, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lovasoa
lovasoa merged commit bcee058 into sql-js:master Nov 17, 2026
2 checks passed
@lovasoa

lovasoa commented Nov 17, 2026

Copy link
Copy Markdown
Member

useful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature-request: support 64bit bigint

3 participants