Skip to content

[Suggestion] Could BigIntColumn return native BigInt values? #400

@farpeter98

Description

@farpeter98

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:

  1. Major version bump — ship as part of the next major release.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions