Alias destroy/destroyAll
This commit is contained in:
parent
6cb53e5001
commit
0ae61d3b53
12
lib/sql.js
12
lib/sql.js
|
@ -201,12 +201,8 @@ BaseSQL.prototype.exists = function (model, id, callback) {
|
|||
};
|
||||
|
||||
BaseSQL.prototype.find = function find(model, id, callback) {
|
||||
var idNumber = Number(id);
|
||||
if (isNaN(idNumber)) {
|
||||
callback(new Error('id is not a number'));
|
||||
}
|
||||
var sql = 'SELECT * FROM ' +
|
||||
this.tableEscaped(model) + ' WHERE ' + this.idColumnEscaped(model) + ' = ' + idNumber + ' LIMIT 1';
|
||||
this.tableEscaped(model) + ' WHERE ' + this.idColumnEscaped(model) + ' = ' + id + ' LIMIT 1';
|
||||
|
||||
this.query(sql, function (err, data) {
|
||||
if (data && data.length === 1) {
|
||||
|
@ -218,16 +214,16 @@ BaseSQL.prototype.find = function find(model, id, callback) {
|
|||
}.bind(this));
|
||||
};
|
||||
|
||||
BaseSQL.prototype.destroy = function destroy(model, id, callback) {
|
||||
BaseSQL.prototype.delete = BaseSQL.prototype.destroy = function destroy(model, id, callback) {
|
||||
var sql = 'DELETE FROM ' +
|
||||
this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + Number(id);
|
||||
this.tableEscaped(model) + ' WHERE ' + this.idColumnEscaped(model) + ' = ' + id;
|
||||
|
||||
this.command(sql, function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
BaseSQL.prototype.destroyAll = function destroyAll(model, callback) {
|
||||
BaseSQL.prototype.deleteAll = BaseSQL.prototype.destroyAll = function destroyAll(model, callback) {
|
||||
this.command('DELETE FROM ' + this.tableEscaped(model), function (err) {
|
||||
if (err) {
|
||||
return callback(err, []);
|
||||
|
|
Loading…
Reference in New Issue