Adding table columns

To add database columns, you simply need to decorate an entity’s properties you want to make into a columnwith a @Column decorator.

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

Now id, name, description, filename, views and isPublished columns will be added to the photo table.Column types in the database are inferred from the property types you used, e.g.number will be converted into integer, string into varchar, boolean into bool, etc.But you can use any column type your database supports by implicitly specifying a column type into the @Column decorator.

We generated a database table with columns, but there is one thing left.Each database table must have a column with a primary key.