不要怂,就是干,撸起袖子干!

You need to sign in or sign up before continuing.
Commit de39cff8 by Gabe Gorelick Committed by Sushant

feat(datatypes): handle numbers passed as objects for bigint (#10496)

1 parent 00e49847
......@@ -14,6 +14,7 @@
"new-cap": [
"warn",
{
"capIsNewExceptionPattern": "^BigInt",
"properties": false
}
],
......
......@@ -146,7 +146,17 @@ NUMBER.prototype.validate = function(value) {
return true;
};
NUMBER.prototype._stringify = function _stringify(number) {
if (typeof number === 'number' || number === null || number === undefined) {
return number;
}
if (typeof number.toString === 'function') {
return number.toString();
}
return number;
};
Object.defineProperty(NUMBER.prototype, 'UNSIGNED', {
get() {
this._unsigned = true;
......
......@@ -55,6 +55,7 @@
"wkx": "^0.4.1"
},
"devDependencies": {
"big-integer": "^1.6.42",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chai-datetime": "^1.5.0",
......
......@@ -11,6 +11,7 @@ const chai = require('chai'),
uuid = require('uuid'),
DataTypes = require('../../lib/data-types'),
dialect = Support.getTestDialect(),
BigInt = require('big-integer'),
semver = require('semver');
describe(Support.getTestDialectTeaser('DataTypes'), () => {
......@@ -207,6 +208,26 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => {
}
});
it('should handle JS BigInt type', function() {
const User = this.sequelize.define('user', {
age: Sequelize.BIGINT
});
const age = BigInt(Number.MAX_SAFE_INTEGER).add(Number.MAX_SAFE_INTEGER);
return User.sync({ force: true }).then(() => {
return User.create({ age });
}).then(user => {
expect(BigInt(user.age).toString()).to.equal(age.toString());
return User.findAll({
where: { age }
});
}).then(users => {
expect(users).to.have.lengthOf(1);
expect(BigInt(users[0].age).toString()).to.equal(age.toString());
});
});
it('calls parse and stringify for DOUBLE', () => {
const Type = new Sequelize.DOUBLE();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!