delete all adonisjs with transactions code example
Example: adonisjs delete rollback transaction
'use strict';
class SafeDelete {
register(Model, customOptions = {}) {
const defaultOptions = {};
const options = Object.assign(defaultOptions, customOptions);
const safeDelete = async function(trx) {
return trx
.from(Model.table)
.where(Model.primaryKey, this[Model.primaryKey])
.del();
};
Model.prototype.safeDelete = safeDelete;
}
}
module.exports = SafeDelete;