Backend Boilerplates typescript Advanced

TypeORM Soft Delete Base Entity

Base entity class with soft delete, createdAt and updatedAt columns for TypeORM.

typescript
import { CreateDateColumn, DeleteDateColumn, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';

export abstract class BaseEntity {
  @PrimaryGeneratedColumn('uuid') id: string;
  @CreateDateColumn() createdAt: Date;
  @UpdateDateColumn() updatedAt: Date;
  @DeleteDateColumn() deletedAt?: Date;
}

// Extend and use withDeleted() to include soft-deleted rows.

Prerequisites

  • typeorm >= 0.3
  • reflect-metadata

Pro Tips

  • → Use softDelete() method on repository.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
typescript
Level
Advanced
Read time
3 min
Published
Sep 2024
License
Commercial License

Newsletter

New modules every week, directly to your inbox.