diff --git a/lib/mysql.js b/lib/mysql.js index 23ae922..ca54630 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -641,6 +641,17 @@ MySQL.prototype.count = function count(model, callback, where) { }; +MySQL.prototype.update = +MySQL.prototype.updateAll = function(model, where, data, cb) { + var query = 'UPDATE ' + this.tableEscaped(model) + ' SET ' + + this.toFields(model, data) + ' ' + this.buildWhere(model, where); + this.query(query, function(err, info) { + var affectedRows = info && typeof info.affectedRows === 'number' ? + info.affectedRows : undefined; + cb && cb(err, {count: affectedRows}); + }); +}; + /** * Delete instances for the given model @@ -657,8 +668,10 @@ MySQL.prototype.destroyAll = function destroyAll(model, where, callback) { } this.query('DELETE FROM ' + this.tableEscaped(model) + ' ' + this.buildWhere(model, where || {}), - function (err, data) { - callback && callback(err, data); + function(err, info) { + var affectedRows = info && typeof info.affectedRows === 'number' ? + info.affectedRows : undefined; + callback && callback(err, {count: affectedRows}); }.bind(this)); };