
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
objection-paranoia
Advanced tools
(https://www.npmjs.com/package/objection-paranoia)
Automatically handle soft-deleting with your Objection.js models.
Install from npm:
npm install objection-paranoia
Register the plugin with an instance of objection:
const objectionSoftDelete = require('objection-paranoia');
objectionSoftDelete.register(objection);
By default, objection-paranoia uses the deleted_at
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, {
columnName: 'deleted_at',
});
columnName: the name of the column to use as the soft delete flag on the model (Default: 'deleted_at'). The column must exist on the table for the model.
You can specify different column names per-model by using the options:
objectionSoftDelete.register(objection, {
columnName: 'deleted_at',
deletedValue: new Date() | knex.fn.now(),
notDeletedValue: null | true | false,
});
deletedValue: you can set this option to allow a different value than "new Date()" to be set in the specified column. For instance, you can use the following code to make a timestamp (you need knex instance to do so)
objectionSoftDelete.register(objection, {
columnName: 'deleted_at',
deletedValue: new Date() | knex.fn.now(),
});
notDeletedValue: you can set (and should) this option along with deletedValue to allow a different value than "null" to be set in the specified column. For instance, you can use the following code to restore the column to null (you need knex instance to do so)
objectionSoftDelete.register(objection, {
columnName: 'deleted_at',
deletedValue: new Date() | knex.fn.now(),
notDeletedValue: null | true | false,
});
When soft-delete is enabled on a model, the delete timestamp will be set to new Date()
on deletion.
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.
MyModel.query().withDeleted();
MyModel.query().forceDelete();
FAQs
A Objectionjs plugin to add soft delete.
We found that objection-paranoia demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.