Create an entity

Entity is your model decorated by an @Entity decorator.A database table will be created for such models.You work with entities everywhere with TypeORM.You can load/insert/update/remove and perform other operations with them.

Let’s make our Photo model as an entity:

  1. import {Entity} from "typeorm";
  2. @Entity()
  3. export class Photo {
  4. id: number;
  5. name: string;
  6. description: string;
  7. filename: string;
  8. views: number;
  9. isPublished: boolean;
  10. }

Now, a database table will be created for the Photo entity and we’ll be able to work with it anywhere in our app.We have created a database table, however what table can exist without columns?Let’s create a few columns in our database table.