3.0.1 • Published 3 years ago

objection-softdelete v3.0.1

Weekly downloads
1,103
License
MIT
Repository
github
Last release
3 years ago

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();
3.0.1

3 years ago

3.0.0

3 years ago

2.0.1

5 years ago

2.0.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago