Sequelize: BIGINT getting truncated due to JS number not support 64 integers

Created on 28 Jun 2015  路  3Comments  路  Source: sequelize/sequelize

JS numbers doesn't support 64 bit integers. There are libraries that offer support like https://www.npmjs.com/package/big-integer

I am trying to store nanoseconds in the database as a BIGINT, but sequelize converts it to a javascript number when it reads it from the database (mysql). This truncates the value to fit inside javascript's range.

Easy way for sequelize to support this is to return the number as a javascript string, if the value won't fit inside the javascript number.

Most helpful comment

You can enable the node mysql options for bigint support like so:

new Sequelize(..., {
  dialectOptions: {
    supportBigNumbers: true,
    bigNumberStrings: true
  }
});

All 3 comments

You will notice that the mysql driver does not cast BIGINT into a number, due to this issue.

https://github.com/felixge/node-mysql/#type-casting

You can enable the node mysql options for bigint support like so:

new Sequelize(..., {
  dialectOptions: {
    supportBigNumbers: true,
    bigNumberStrings: true
  }
});

K thanks. It might be useful to document this near the BIGINT documentation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GuilhermeReda picture GuilhermeReda  路  3Comments

haikyuu picture haikyuu  路  3Comments

hendrul picture hendrul  路  3Comments

mujz picture mujz  路  3Comments

couds picture couds  路  3Comments