Instructs the model to set a timestamp when deleting, rather than actually removing the record from the database.
By default, the SoftDelete decorator will expect a deletedAt field to be set on your model, pointing to a timestamp field in the database, like so:
deletedAt
timestamp
export async function up(db: Kysely<any>): Promise<void> { await db.schema .createTable('posts') .addColumn('id', 'bigserial', col => col.primaryKey()) .addColumn('deleted_at', 'timestamp', col => col.defaultTo(null)) .addColumn('created_at', 'timestamp', col => col.notNull()) .addColumn('updated_at', 'timestamp', col => col.notNull()) .execute()}@SoftDelete()class Post extends ApplicationModel {} Copy
export async function up(db: Kysely<any>): Promise<void> { await db.schema .createTable('posts') .addColumn('id', 'bigserial', col => col.primaryKey()) .addColumn('deleted_at', 'timestamp', col => col.defaultTo(null)) .addColumn('created_at', 'timestamp', col => col.notNull()) .addColumn('updated_at', 'timestamp', col => col.notNull()) .execute()}@SoftDelete()class Post extends ApplicationModel {}
If you would like to use a different column to hold the deleted status, you can specify a custom column in your model, like so:
@SoftDelete() class Post extends ApplicationModel { public get deletedAtField() { return 'customDatetimeField' as const } }
Instructs the model to set a timestamp when deleting, rather than actually removing the record from the database.
By default, the SoftDelete decorator will expect a
deletedAtfield to be set on your model, pointing to atimestampfield in the database, like so:If you would like to use a different column to hold the deleted status, you can specify a custom column in your model, like so:
@SoftDelete() class Post extends ApplicationModel { public get deletedAtField() { return 'customDatetimeField' as const } }