npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@eienjs/adonisjs-soft-deletes

v1.0.2

Published

Provider-based Soft deletes for AdonisJS

Downloads

707

Readme

@eienjs/adonisjs-soft-deletes

Source Code Npm Node Version Support Latest Version Software License Build Status Total Downloads

Provider-based Soft deletes for AdonisJS with full Lucid ORM support.

Features

  • Full Lucid ORM Integration: Automatic query filtering (deleted_at is null), eager relationship filtering, and ModelQueryBuilder macros.
  • Fluent Querying: User.query().withTrashed(), User.query().onlyTrashed(), User.query().restore(), plus static helpers User.withTrashed() and User.onlyTrashed().
  • Instance Helpers: .$trashed boolean getter, .delete() (soft delete), .restore(), and .forceDelete().

Quick Start

Install the package using the following command:

node ace add @eienjs/adonisjs-soft-deletes

This will register the Lucid provider in your adonisrc.ts file:

export default defineConfig({
  providers: [
    () => import('@eienjs/adonisjs-soft-deletes/providers/lucid_provider'),
  ],
});

Usage

1. Database Migration

Ensure your database table includes a nullable deleted_at timestamp:

import { BaseSchema } from '@adonisjs/lucid/schema';

export default class UsersTable extends BaseSchema {
  protected tableName = 'users';

  public async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id');
      table.string('email').notNullable();
      table.timestamp('deleted_at').nullable();
      table.timestamp('created_at').notNullable();
      table.timestamp('updated_at').nullable();
    });
  }

  public async down() {
    this.schema.dropTable(this.tableName);
  }
}

2. Model Definition

Apply the SoftDeletes mixin to your Lucid model:

import { compose } from '@adonisjs/core/helpers';
import { BaseModel } from '@adonisjs/lucid/orm';
import { SoftDeletes } from '@eienjs/adonisjs-soft-deletes/lucid/mixin';

export default class User extends compose(BaseModel, SoftDeletes) {
  // Model properties and columns...
}

3. Soft Deleting and Restoring Records

// Find a record and soft delete
const user = await User.findOrFail(1);
await user.delete(); // Sets deleted_at to current timestamp

console.log(user.$trashed); // true

// Restore soft-deleted record
await user.restore();
console.log(user.$trashed); // false

// Permanently delete from database
await user.forceDelete();

4. Querying Records

By default, queries automatically exclude soft-deleted records:

// Excludes soft-deleted records automatically
const activeUsers = await User.all();

// Include soft-deleted records via query builder
const allUsers = await User.query().withTrashed();

// Retrieve only soft-deleted records via query builder
const archivedUsers = await User.query().onlyTrashed();

// Bulk restore soft-deleted records via query builder
await User.query().onlyTrashed().where('status', 'inactive').restore();

// Static helpers on model
const all = await User.withTrashed();
const archived = await User.onlyTrashed();

Documentation

The documentation is available on EienJS.

Contributing

Contributions are welcome. Please read CONTRIBUTING for more details and remember to check the CHANGELOG file.

Copyright and License

The @eienjs/adonisjs-soft-deletes library is licensed for use under the MIT License (MIT). Please see LICENSE for more information.