Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

64bit integer in JavaScript, from Mysql request

I have this number 76561197993482001 (64bit int) stored as a bigint(20) in my database.

But when I try to fetch it using :

//node.js
    query('SELECT * FROM table',function(err,rows){
      console.log(rows[0]["id"]);// I get 76561197993482000
      });

I get the wrong number. I guess this is because js can't handle 64bit variables.

I know there are libraries for bigint in js but This number is directly stored in the rows variable. So How can I do?

Is there a way to convert it as a text when I send the request?

like image 987
lopata Avatar asked May 23 '26 20:05

lopata


1 Answers

Depending on what middleware you're using, most of them have a setting that enables support for big numbers, the most common middleware uses the supportBigNumbers option for this

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host              : 'example.org',
  user              : 'bob',
  password          : 'secret',
  supportBigNumbers : true
});
like image 140
adeneo Avatar answered May 25 '26 08:05

adeneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!