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

Commit 235b3968 by User4martin

make Query.formatBindParameters static

1 parent 5eb25bf0
...@@ -394,7 +394,7 @@ var groupJoinData = function(rows, includeOptions, options) { ...@@ -394,7 +394,7 @@ var groupJoinData = function(rows, includeOptions, options) {
* skipUnescape: bool, skip unescaping $$ * skipUnescape: bool, skip unescaping $$
* skipValueReplace: bool, do not replace (but do unescape $$). Check correct syntax and if all values are available * skipValueReplace: bool, do not replace (but do unescape $$). Check correct syntax and if all values are available
*/ */
AbstractQuery.prototype.formatBindParameters = function(sql, values, dialect, replacementFunc, options) { AbstractQuery.formatBindParameters = function(sql, values, dialect, replacementFunc, options) {
if (!values) { if (!values) {
return [sql, []]; return [sql, []];
} }
......
...@@ -24,6 +24,7 @@ Query.prototype.getInsertIdField = function() { ...@@ -24,6 +24,7 @@ Query.prototype.getInsertIdField = function() {
return 'id'; return 'id';
}; };
Query.formatBindParameters = AbstractQuery.formatBindParameters;
Query.prototype.run = function(sql, parameters) { Query.prototype.run = function(sql, parameters) {
var self = this; var self = this;
this.sql = sql; this.sql = sql;
......
...@@ -21,6 +21,7 @@ var Query = function(connection, sequelize, options) { ...@@ -21,6 +21,7 @@ var Query = function(connection, sequelize, options) {
}; };
Utils.inherit(Query, AbstractQuery); Utils.inherit(Query, AbstractQuery);
Query.formatBindParameters = AbstractQuery.formatBindParameters;
Query.prototype.run = function(sql, parameters) { Query.prototype.run = function(sql, parameters) {
var self = this; var self = this;
this.sql = sql; this.sql = sql;
......
...@@ -90,11 +90,11 @@ Query.prototype.parseDialectSpecificFields = parseDialectSpecificFields; ...@@ -90,11 +90,11 @@ Query.prototype.parseDialectSpecificFields = parseDialectSpecificFields;
/** /**
* rewrite query with parameters * rewrite query with parameters
*/ */
Query.prototype.formatBindParameters = function(sql, values, dialect) { Query.formatBindParameters = function(sql, values, dialect) {
var bindParam = []; var bindParam = [];
if (Array.isArray(values)) { if (Array.isArray(values)) {
bindParam = values; bindParam = values;
sql = this.parent.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0]; sql = AbstractQuery.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0];
} else { } else {
var i = 0; var i = 0;
var seen = {}; var seen = {};
...@@ -110,7 +110,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) { ...@@ -110,7 +110,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) {
} }
return undefined; return undefined;
}; };
sql = this.parent.formatBindParameters(sql, values, dialect, replacementFunc)[0]; sql = AbstractQuery.formatBindParameters(sql, values, dialect, replacementFunc)[0];
} }
return [sql, bindParam]; return [sql, bindParam];
}; };
......
...@@ -27,14 +27,14 @@ Query.prototype.getInsertIdField = function() { ...@@ -27,14 +27,14 @@ Query.prototype.getInsertIdField = function() {
/** /**
* rewrite query with parameters * rewrite query with parameters
*/ */
Query.prototype.formatBindParameters = function(sql, values, dialect) { Query.formatBindParameters = function(sql, values, dialect) {
var bindParam = []; var bindParam = [];
if (Array.isArray(values)) { if (Array.isArray(values)) {
bindParam = {}; bindParam = {};
values.forEach(function(v, i) { values.forEach(function(v, i) {
bindParam['$'+(i+1)] = v; bindParam['$'+(i+1)] = v;
}); });
sql = this.parent.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0]; sql = AbstractQuery.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0];
} else { } else {
bindParam = {}; bindParam = {};
if (typeof values === 'object') { if (typeof values === 'object') {
...@@ -42,7 +42,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) { ...@@ -42,7 +42,7 @@ Query.prototype.formatBindParameters = function(sql, values, dialect) {
bindParam['$'+k] = values[k]; bindParam['$'+k] = values[k];
}); });
} }
sql = this.parent.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0]; sql = AbstractQuery.formatBindParameters(sql, values, dialect, { skipValueReplace: true })[0];
} }
return [sql, bindParam]; return [sql, bindParam];
}; };
...@@ -55,7 +55,7 @@ Query.prototype.run = function(sql, parameters) { ...@@ -55,7 +55,7 @@ Query.prototype.run = function(sql, parameters) {
var method = self.getDatabaseMethod(); var method = self.getDatabaseMethod();
if (method === 'exec') { if (method === 'exec') {
// exec does not support bind parameter // exec does not support bind parameter
sql = this.parent.formatBindParameters(sql, self.options.bind, self.options.dialect, { skipUnescape: true })[0]; sql = AbstractQuery.formatBindParameters(sql, self.options.bind, self.options.dialect, { skipUnescape: true })[0];
this.sql = sql; this.sql = sql;
} }
......
...@@ -739,7 +739,7 @@ Sequelize.prototype.query = function(sql, options) { ...@@ -739,7 +739,7 @@ Sequelize.prototype.query = function(sql, options) {
} }
var bindParameters; var bindParameters;
if (options.bind) { if (options.bind) {
var bindSql = self.dialect.Query.prototype.formatBindParameters(sql, options.bind, this.options.dialect); var bindSql = self.dialect.Query.formatBindParameters(sql, options.bind, this.options.dialect);
sql = bindSql[0]; sql = bindSql[0];
bindParameters = bindSql[1]; bindParameters = bindSql[1];
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!