sequelize js with big integers

旧巷老猫 提交于 2019-12-23 10:09:56

问题


I have an application written in Node JS and uses the Sequelize js ORM library to access my database which is MySql.

My problem is that I have a column in my db which is BIGINT and when the value of it is large I get wrong values when I retrieve it.

for example when the value in database is: 10205918797953057 I get 10205918797953056 when I get it using sequelize.

I tried using big-integer library but I had no luck.

any advice is welcomed.

P.S: I can't change the datatype to VARCHAR.


回答1:


You should enable supportBigNumbers and possibly bigNumberStrings on the mysql module: https://github.com/felixge/node-mysql#connection-options

new Sequelize(..., {
  dialect: 'mysql',
  dialectOptions: {
    supportBigNumbers: true
  }
});


来源:https://stackoverflow.com/questions/28433139/sequelize-js-with-big-integers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!