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

Commit 9f2d2226 by Felix Becker Committed by Jan Aagaard Meier

Use typeof instead of _.isPlainObject (#6414)

Enables support of sql-template-strings
1 parent cc555ab8
...@@ -545,7 +545,7 @@ class Sequelize { ...@@ -545,7 +545,7 @@ class Sequelize {
options.fieldMap = options.model.fieldAttributeMap; options.fieldMap = options.model.fieldAttributeMap;
} }
if (_.isPlainObject(sql)) { if (typeof sql === 'object') {
if (sql.values !== undefined) { if (sql.values !== undefined) {
if (options.replacements !== undefined) { if (options.replacements !== undefined) {
throw new Error('Both `sql.values` and `options.replacements` cannot be set at the same time'); throw new Error('Both `sql.values` and `options.replacements` cannot be set at the same time');
......
...@@ -497,6 +497,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() { ...@@ -497,6 +497,22 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
}); });
}); });
it('it allows to pass custom class instances', function() {
let logSql;
class SQLStatement {
constructor() {
this.values = [1, 2];
}
get query() {
return 'select ? as foo, ? as bar';
}
}
return this.sequelize.query(new SQLStatement(), { type: this.sequelize.QueryTypes.SELECT, logging: s => logSql = s } ).then(result => {
expect(result).to.deep.equal([{ foo: 1, bar: 2 }]);
expect(logSql.indexOf('?')).to.equal(-1);
});
});
it('uses properties `query` and `values` if query is tagged', function() { it('uses properties `query` and `values` if query is tagged', function() {
var logSql; var logSql;
return this.sequelize.query({ query: 'select ? as foo, ? as bar', values: [1, 2] }, { type: this.sequelize.QueryTypes.SELECT, logging: function(s) { logSql = s; } }).then(function(result) { return this.sequelize.query({ query: 'select ? as foo, ? as bar', values: [1, 2] }, { type: this.sequelize.QueryTypes.SELECT, logging: function(s) { logSql = s; } }).then(function(result) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!