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

Commit 3d71f043 by Mick Hansen

Just ONE type of incrementQuery

1 parent 0e82a72a
...@@ -190,8 +190,35 @@ module.exports = (function() { ...@@ -190,8 +190,35 @@ module.exports = (function() {
OR a string with conditions (e.g. 'name="foo"'). OR a string with conditions (e.g. 'name="foo"').
If you use a string, you have to escape it on your own. If you use a string, you have to escape it on your own.
*/ */
incrementQuery: function(tableName, values, where) { incrementQuery: function(tableName, attrValueHash, where, options) {
throwMethodUndefined('incrementQuery') attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull)
var query
, values = []
query = "UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
if (this._dialect.supports['RETURNING']) {
query += " RETURNING *"
}
for (var key in attrValueHash) {
var value = attrValueHash[key]
values.push(this.quoteIdentifier(key) + "=" + this.quoteIdentifier(key) + " + " + this.escape(value))
}
options = options || {}
for (var key in options) {
var value = options[key];
values.push(this.quoteIdentifier(key) + "=" + this.escape(value))
}
var replacements = {
table: this.quoteIdentifiers(tableName),
values: values.join(","),
where: this.getWhereConditions(where)
}
return Utils._.template(query)(replacements)
}, },
/* /*
......
...@@ -238,33 +238,6 @@ module.exports = (function() { ...@@ -238,33 +238,6 @@ module.exports = (function() {
return query return query
}, },
incrementQuery: function (tableName, attrValueHash, where, options) {
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull)
var values = []
for (var key in attrValueHash) {
var value = attrValueHash[key]
, _value = this.escape(value)
values.push(this.quoteIdentifier(key) + "=" + this.quoteIdentifier(key) + " + " + _value)
}
options = options || {}
for (var key in options) {
var value = options[key];
values.push(this.quoteIdentifier(key) + "=" + this.escape(value))
}
var table = this.quoteIdentifier(tableName)
values = values.join(",")
where = this.getWhereConditions(where)
var query = "UPDATE " + table + " SET " + values + " WHERE " + where
return query
},
addIndexQuery: function(tableName, attributes, options) { addIndexQuery: function(tableName, attributes, options) {
var transformedAttributes = attributes.map(function(attribute) { var transformedAttributes = attributes.map(function(attribute) {
if(typeof attribute === 'string') { if(typeof attribute === 'string') {
......
...@@ -371,33 +371,6 @@ module.exports = (function() { ...@@ -371,33 +371,6 @@ module.exports = (function() {
return Utils._.template(query)(replacements) return Utils._.template(query)(replacements)
}, },
incrementQuery: function(tableName, attrValueHash, where, options) {
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull)
var query = "UPDATE <%= table %> SET <%= values %> WHERE <%= where %> RETURNING *"
, values = []
for (var key in attrValueHash) {
var value = attrValueHash[key]
values.push(this.quoteIdentifier(key) + "=" + this.quoteIdentifier(key) + " + " + this.escape(value))
}
options = options || {}
for (var key in options) {
var value = options[key];
values.push(this.quoteIdentifier(key) + "=" + this.escape(value))
}
var replacements = {
table: this.quoteIdentifiers(tableName),
values: values.join(","),
where: this.getWhereConditions(where)
}
return Utils._.template(query)(replacements)
},
addIndexQuery: function(tableName, attributes, options) { addIndexQuery: function(tableName, attributes, options) {
var transformedAttributes = attributes.map(function(attribute) { var transformedAttributes = attributes.map(function(attribute) {
if (typeof attribute === 'string') { if (typeof attribute === 'string') {
......
...@@ -214,32 +214,6 @@ module.exports = (function() { ...@@ -214,32 +214,6 @@ module.exports = (function() {
return Utils._.template(query)(replacements) return Utils._.template(query)(replacements)
}, },
incrementQuery: function(tableName, attrValueHash, where, options) {
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, this.options.omitNull)
var query = "UPDATE <%= table %> SET <%= values %> WHERE <%= where %>"
, values = []
for (var key in attrValueHash) {
var value = attrValueHash[key]
values.push(this.quoteIdentifier(key) + "=" + this.quoteIdentifier(key) + "+ " + this.escape(value))
}
options = options || {}
for (var key in options) {
var value = options[key];
values.push(this.quoteIdentifier(key) + "=" + this.escape(value))
}
var replacements = {
table: this.quoteIdentifier(tableName),
values: values.join(","),
where: this.getWhereConditions(where)
}
return Utils._.template(query)(replacements)
},
attributesToSQL: function(attributes) { attributesToSQL: function(attributes) {
var result = {} var result = {}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!