Return count when updating or deleting models
This commit is contained in:
parent
71fda816ba
commit
ff538b09c8
17
lib/mysql.js
17
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));
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue