Problem
Currently the BigInt SQL type is converted into JS Number values in the driver - the former is a 64 bit integer, the latter is a 64 bit float, so there's a possible precision loss there.
I looked through the wiki and the previous issues and found that specifically for this the setUseNumericString option can be set to make the driver return strings instead - however, this applies to all number conversions, which, while not deal breaking, is a bit of a nuisance.
Suggestion
Couldn't we simply use JS BigInt values? I tried the modification locally, this got me the desired behaviour.
diff --git a/cpp/include/js/columns/big_int_column.h b/cpp/include/js/columns/big_int_column.h
index 8edaeb34..0d3a9a3c 100644
--- a/cpp/include/js/columns/big_int_column.h
+++ b/cpp/include/js/columns/big_int_column.h
@@ -24,7 +24,7 @@ class BigIntColumn : public Column {
}
inline Napi::Object ToNative(Napi::Env env) override {
- return Napi::Number::New(env, value).As<Napi::Object>();
+ return Napi::BigInt::New(env, value).As<Napi::Object>();
}
private:
Test Results
Full test suite passes with the change applied (Windows, Node v22.13.0, ODBC Driver 18, Trusted Connection):
695 passing (3m)
2 pending
The 2 pending tests are:
- multiple-errors.test.js → "non trusted invalid user" — explicitly marked with it.skip().
- encrypt-verification.test.js → "should verify Always Encrypted is actually working..." — skipped because I used trusted connection without encryption
Breaking Change Considerations
This is a breaking change for consumers that perform arithmetic or comparisons with Number on BIGINT columns (e.g. row.id + 1 becomes a TypeError when row.id is a BigInt). Possible mitigations:
- Major version bump — ship as part of the next major release.
- Opt-in flag — add a connection/query option like
{ bigIntAsNative: true } (default false) so users can migrate at their own pace; flip the default in the next major.
Problem
Currently the
BigIntSQL type is converted into JSNumbervalues in the driver - the former is a 64 bit integer, the latter is a 64 bit float, so there's a possible precision loss there.I looked through the wiki and the previous issues and found that specifically for this the
setUseNumericStringoption can be set to make the driver return strings instead - however, this applies to all number conversions, which, while not deal breaking, is a bit of a nuisance.Suggestion
Couldn't we simply use JS
BigIntvalues? I tried the modification locally, this got me the desired behaviour.Test Results
Full test suite passes with the change applied (Windows, Node v22.13.0, ODBC Driver 18, Trusted Connection):
The 2 pending tests are:
Breaking Change Considerations
This is a breaking change for consumers that perform arithmetic or comparisons with
Numberon BIGINT columns (e.g.row.id + 1becomes aTypeErrorwhenrow.idis aBigInt). Possible mitigations:{ bigIntAsNative: true }(defaultfalse) so users can migrate at their own pace; flip the default in the next major.