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

Commit 5adaf109 by Gabe Gorelick Committed by Sushant

feat(data-types): handle numbers passed as objects (#10492)

1 parent 5cdd3bf7
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
"new-cap": [ "new-cap": [
"error", "error",
{ {
"capIsNewExceptionPattern": "^BigInt",
"properties": false "properties": false
} }
], ],
......
...@@ -214,6 +214,17 @@ NUMBER.prototype.validate = function(value) { ...@@ -214,6 +214,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;
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
"@types/bluebird": "^3.5.26", "@types/bluebird": "^3.5.26",
"@types/node": "^10.12.27", "@types/node": "^10.12.27",
"@types/validator": "^10.9.0", "@types/validator": "^10.9.0",
"big-integer": "^1.6.42",
"chai": "^4.x", "chai": "^4.x",
"chai-as-promised": "^7.x", "chai-as-promised": "^7.x",
"chai-datetime": "^1.x", "chai-datetime": "^1.x",
......
...@@ -12,6 +12,7 @@ const chai = require('chai'), ...@@ -12,6 +12,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'), () => {
...@@ -227,6 +228,26 @@ describe(Support.getTestDialectTeaser('DataTypes'), () => { ...@@ -227,6 +228,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 bindParam for DOUBLE', () => { it('calls parse and bindParam 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!