objection-softdelete

3.0.1 • Public • Published

objection-softdelete

npm

Automatically handle soft-deleting with your Objection.js models.

Installation

Install from npm:

npm install objection-softdelete

Register the plugin with an instance of objection:

const objectionSoftDelete = require('objection-softdelete');
objectionSoftDelete.register(objection);

Configuration

By default, objection-softdelete uses the deletedAt attribute for soft-deletes. You can optionally pass in an options object as the second argument to register to specify a custom attribute to use:

objectionSoftDelete.register(objection, {
  deleteAttr: 'deletedOn'
});

Usage

When soft-delete is enabled on a model, the delete timestamp will be set to new Date() on deletion.

Enable soft-delete for a model

Set the softDelete static property on your model to true:

class MyModel {
  static get softDelete() {
    return true;
  }
}

When softDelete is enabled, all delete queries to this model will instead update the model with a delete timestamp, and all queries to find these models will omit deleted instances.

Include deleted records in query

MyModel.query().includeDeleted();

Force delete

MyModel.query().forceDelete();

Readme

Keywords

none

Package Sidebar

Install

npm i objection-softdelete

Weekly Downloads

1,021

Version

3.0.1

License

MIT

Unpacked Size

17.9 kB

Total Files

15

Last publish

Collaborators

  • ackerdev