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

Commit 44ad6bab by Sushant Committed by GitHub

fix(where): show inspected value for incorrect where conditions (#8481)

1 parent 4ff64088
'use strict'; 'use strict';
const dataTypes = require('./data-types'); const dataTypes = require('./data-types');
const util = require('util');
const _ = require('lodash'); const _ = require('lodash');
function escape(val, timeZone, dialect, format) { function escape(val, timeZone, dialect, format) {
...@@ -47,7 +48,7 @@ function escape(val, timeZone, dialect, format) { ...@@ -47,7 +48,7 @@ function escape(val, timeZone, dialect, format) {
} }
if (!val.replace) { if (!val.replace) {
throw new Error('Invalid value ' + val); throw new Error('Invalid value ' + util.inspect(val));
} }
if (dialect === 'postgres' || dialect === 'sqlite' || dialect === 'mssql') { if (dialect === 'postgres' || dialect === 'sqlite' || dialect === 'mssql') {
......
...@@ -19,25 +19,25 @@ describe('QueryGenerator', () => { ...@@ -19,25 +19,25 @@ describe('QueryGenerator', () => {
it('should not parse any strings as aliases operators', function() { it('should not parse any strings as aliases operators', function() {
const QG = getAbstractQueryGenerator(this.sequelize); const QG = getAbstractQueryGenerator(this.sequelize);
expect(() => QG.whereItemQuery('$or', [{test: 5}, {test: 3}])) expect(() => QG.whereItemQuery('$or', [{test: 5}, {test: 3}]))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { test: 5 }');
expect(() => QG.whereItemQuery('$and', [{test: 5}, {test: 3}])) expect(() => QG.whereItemQuery('$and', [{test: 5}, {test: 3}]))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { test: 5 }');
expect(() => QG.whereItemQuery('test', {$gt: 5})) expect(() => QG.whereItemQuery('test', {$gt: 5}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$gt\': 5 }');
expect(() => QG.whereItemQuery('test', {$between: [2, 5]})) expect(() => QG.whereItemQuery('test', {$between: [2, 5]}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$between\': [ 2, 5 ] }');
expect(() => QG.whereItemQuery('test', {$ne: 3})) expect(() => QG.whereItemQuery('test', {$ne: 3}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$ne\': 3 }');
expect(() => QG.whereItemQuery('test', {$not: 3})) expect(() => QG.whereItemQuery('test', {$not: 3}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$not\': 3 }');
expect(() => QG.whereItemQuery('test', {$in: [4]})) expect(() => QG.whereItemQuery('test', {$in: [4]}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$in\': [ 4 ] }');
}); });
it('should parse set aliases strings as operators', function() { it('should parse set aliases strings as operators', function() {
...@@ -57,31 +57,31 @@ describe('QueryGenerator', () => { ...@@ -57,31 +57,31 @@ describe('QueryGenerator', () => {
.should.be.equal('(test BETWEEN 2 AND 5 AND test != 3 AND test > 4)'); .should.be.equal('(test BETWEEN 2 AND 5 AND test != 3 AND test > 4)');
expect(() => QG.whereItemQuery('OR', [{test: {'^^': 5}}, {test: {$not: 3}}, {test: {[Op.in]: [4]}}])) expect(() => QG.whereItemQuery('OR', [{test: {'^^': 5}}, {test: {$not: 3}}, {test: {[Op.in]: [4]}}]))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$not\': 3 }');
expect(() => QG.whereItemQuery('OR', [{test: {$gt: 5}}, {test: {'!': 3}}, {test: {[Op.in]: [4]}}])) expect(() => QG.whereItemQuery('OR', [{test: {$gt: 5}}, {test: {'!': 3}}, {test: {[Op.in]: [4]}}]))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$gt\': 5 }');
expect(() => QG.whereItemQuery('$or', [{test: 5}, {test: 3}])) expect(() => QG.whereItemQuery('$or', [{test: 5}, {test: 3}]))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { test: 5 }');
expect(() => QG.whereItemQuery('$and', [{test: 5}, {test: 3}])) expect(() => QG.whereItemQuery('$and', [{test: 5}, {test: 3}]))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { test: 5 }');
expect(() => QG.whereItemQuery('test', {$gt: 5})) expect(() => QG.whereItemQuery('test', {$gt: 5}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$gt\': 5 }');
expect(() => QG.whereItemQuery('test', {$between: [2, 5]})) expect(() => QG.whereItemQuery('test', {$between: [2, 5]}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$between\': [ 2, 5 ] }');
expect(() => QG.whereItemQuery('test', {$ne: 3})) expect(() => QG.whereItemQuery('test', {$ne: 3}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$ne\': 3 }');
expect(() => QG.whereItemQuery('test', {$not: 3})) expect(() => QG.whereItemQuery('test', {$not: 3}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$not\': 3 }');
expect(() => QG.whereItemQuery('test', {$in: [4]})) expect(() => QG.whereItemQuery('test', {$in: [4]}))
.to.throw('Invalid value [object Object]'); .to.throw('Invalid value { \'$in\': [ 4 ] }');
}); });
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!