Registry /
database / adonis-lucid-soft-deletes
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SoftDeletes
✓ import { SoftDeletes } from 'adonis-lucid-soft-deletes'
✗ const { SoftDeletes } = require('adonis-lucid-soft-deletes')
ESM-only package; CommonJS require not supported.
provider
✓ () => import('adonis-lucid-soft-deletes/provider')
✗ 'adonis-lucid-soft-deletes/provider'
Provider must be a lazy import function in adonisrc.ts, not a string.
compose
✓ import { compose } from '@adonisjs/core/helpers'
✗ import { compose } from 'adonis-lucid-soft-deletes'
compose is part of AdonisJS core, not this package.
Complete setup: install, configure provider, migration with deleted_at, model with SoftDeletes mixin, and controller actions for delete, restore, and show with trashed check.
// Install: npm i adonis-lucid-soft-deletes && node ace configure adonis-lucid-soft-deletes
// In adonisrc.ts, add provider:
// providers: [
// () => import('adonis-lucid-soft-deletes/provider'),
// ]
// Migration: add timestamp column
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'users'
async up() {
this.schema.createTable(this.tableName, (table) => {
table.increments('id')
table.string('email')
table.timestamp('deleted_at').nullable()
})
}
async down() {
this.schema.dropTable(this.tableName)
}
}
// Model: apply mixin
import { DateTime } from 'luxon'
import { BaseModel, column } from '@adonisjs/lucid/orm'
import { compose } from '@adonisjs/core/helpers'
import { SoftDeletes } from 'adonis-lucid-soft-deletes'
export default class User extends compose(BaseModel, SoftDeletes) {
@column({ isPrimary: true })
declare id: number
@column()
declare email: string
@column.dateTime()
declare deletedAt: DateTime | null
}
// Usage in controller
import User from '#models/user'
export default class UsersController {
async destroy({ params, response }) {
const user = await User.findOrFail(params.id)
await user.delete()
response.noContent()
}
async show({ params }) {
const user = await User.withTrashed().where('id', params.id).firstOrFail()
if (user.trashed) {
return response.forbidden()
}
return user
}
async restore({ params }) {
const user = await User.withTrashed().where('id', params.id).firstOrFail()
await user.restore()
return user
}
}
Errors
Common errors & fixes
Error: Cannot find module 'adonis-lucid-soft-deletes/provider'
Provider not imported correctly in adonisrc.ts.
fixUse lazy import: `() => import('adonis-lucid-soft-deletes/provider')` Property 'withTrashed' does not exist on type 'typeof User'
Model does not use SoftDeletes mixin or it is not imported.
fixApply mixin: `export default class User extends compose(BaseModel, SoftDeletes)`
TypeError: user.restore is not a function
Calling restore on non-soft-deleted model or missing mixin.
fixEnsure model uses SoftDeletes mixin and call restore on soft-deleted instance.
ER_BAD_NULL_ERROR: Column 'deleted_at' cannot be null
Migration defines deleted_at as NOT NULL.
fixUse `.nullable()` in migration: `table.timestamp('deleted_at').nullable()` Audit
Dependencies
@adonisjs/corerequiredCore framework dependency for `compose` helper and providers.
@adonisjs/lucidrequiredORM dependency for model base class and query builder extensions.