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

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 @@ ...@@ -14,6 +14,7 @@
"new-cap": [ "new-cap": [
"warn", "warn",
{ {
"capIsNewExceptionPattern": "^BigInt",
"properties": false "properties": false
} }
], ],
......
...@@ -146,7 +146,17 @@ NUMBER.prototype.validate = function(value) { ...@@ -146,7 +146,17 @@ NUMBER.prototype.validate = function(value) {
return true; 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', { Object.defineProperty(NUMBER.prototype, 'UNSIGNED', {
get() { get() {
this._unsigned = true; this._unsigned = true;
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
"wkx": "^0.4.1" "wkx": "^0.4.1"
}, },
"devDependencies": { "devDependencies": {
"big-integer": "^1.6.42",
"chai": "^4.1.2", "chai": "^4.1.2",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"chai-datetime": "^1.5.0", "chai-datetime": "^1.5.0",
......
...@@ -11,6 +11,7 @@ const chai = require('chai'), ...@@ -11,6 +11,7 @@ const chai = require('chai'),
uuid = require('uuid'), uuid = require('uuid'),
DataTypes = require('../../lib/data-types'), DataTypes = require('../../lib/data-types'),
dialect = Support.getTestDialect(), dialect = Support.getTestDialect(),
BigInt = require('big-integer'),
semver = require('semver'); semver = require('semver');
describe(Support.getTestDialectTeaser('DataTypes'), () => { describe(Support.getTestDialectTeaser('DataTypes'), () => {
...@@ -207,6 +208,26 @@ 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', () => { it('calls parse and stringify for DOUBLE', () => {
const Type = new Sequelize.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!