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

Support JavaScript BigInt primitive for MySQL BIGINT type #3113

Open
yshrsmz opened this issue Oct 13, 2024 · 2 comments
Open

Support JavaScript BigInt primitive for MySQL BIGINT type #3113

yshrsmz opened this issue Oct 13, 2024 · 2 comments

Comments

@yshrsmz
Copy link

yshrsmz commented Oct 13, 2024

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt

Instead of treating MySQL BIGINT as String, It would be great if we could use JavaScript BigInt primitive.

@erikschul
Copy link

This can fail silently by downcasting a bigint returned from the database into a JS number, causing data loss if the same value is later saved, for example SELECT followed by UPDATE.

In TypeScript, when casting the rows to types, the downcast is not obvious.
Luckily this was caught using integration tests.

@erikschul
Copy link

The connection can be configured to return strings, but why not use native types? @sidorares


  /**
   * When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option
   * (Default: false)
   */
  supportBigNumbers?: boolean;

  /**
   * Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be
   * always returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving
   * bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately
   * represented with [JavaScript Number objects](https://262.ecma-international.org/5.1/#sec-8.5)
   * (which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as Number objects.
   * This option is ignored if supportBigNumbers is disabled.
   */
  bigNumberStrings?: boolean;

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

No branches or pull requests

3 participants