Getting Started
Installation
Install and configure @eienjs/adonisjs-soft-deletes in your AdonisJS application.
Install and configure the package using the AdonisJS Ace CLI, or set it up manually.
Quick Installation
Run the ace add command to install the package and automatically register its provider in adonisrc.ts:
node ace add @eienjs/adonisjs-soft-deletes
Manual Installation
If you prefer installing the package manually, first install it with your package manager:
pnpm add @eienjs/adonisjs-soft-deletes
npm install @eienjs/adonisjs-soft-deletes
yarn add @eienjs/adonisjs-soft-deletes
Then execute the configure command or register the provider directly in your adonisrc.ts file:
adonisrc.ts
import { defineConfig } from '@adonisjs/core/app';
export default defineConfig({
providers: [
// ... other providers
() => import('@eienjs/adonisjs-soft-deletes/providers/lucid_provider'),
],
});
Importing
@eienjs/adonisjs-soft-deletes/providers/lucid_provider in adonisrc.ts also loads the TypeScript module augmentations for ModelQueryBuilder and ModelQueryBuilderContract.Database Migration
Tables backing models with soft deletes must include a nullable deleted_at timestamp column (or a custom column name configured on the model):
database/migrations/create_users_table.ts
import { BaseSchema } from '@adonisjs/lucid/schema';
export default class CreateUsersTable extends BaseSchema {
protected tableName = 'users';
public async up(): Promise<void> {
this.schema.createTable(this.tableName, (table) => {
table.increments('id');
table.string('email').notNullable().unique();
table.timestamp('created_at').notNullable();
table.timestamp('updated_at').nullable();
table.timestamp('deleted_at').nullable();
});
}
public async down(): Promise<void> {
this.schema.dropTable(this.tableName);
}
}
Next, learn how to apply the mixin and work with soft-deleted records in the Usage guide.
