Base Model

You can create a base-mode.ts file, that is the global abstraction of all the entities you will create in your project.

import {
  CreateDateColumn,
  Generated,
  PrimaryColumn,
  UpdateDateColumn,
} from 'typeorm';

export class BaseModel {
  @PrimaryColumn({ type: 'uuid' })
  @Generated('uuid')
  public id?: string;

  @CreateDateColumn()
  public createdAt?: Date;

  @UpdateDateColumn()
  public updatedAt?: Date;
}

Now to create a new entity, you just need to inherit from the BaseModel class and declare the specific fields for that entity.

Last updated

Was this helpful?