Creating TypeORM entities
In this part, we'll create entities that represent our social network database. An entity is a TypeScript class that has been annotated with the @Entity()
decorator that corresponds to a database table.
When working with a database using plain SQL rather than an ORM, you begin by creating database tables. With TypeORM, we must also begin by creating entities.
Add the @Entity()
decorator to the class definition and the @Column
(or equivalent) decorator to each property in the class to create an entity. These annotations provide TypeORM with the information it needs to create the database table and columns.
We can also use the following decorators to establish associations between the entities:
OneToOne
: This is used to create a one-to-one relationship between two objects.JoinColumn
: This specifies which part of the relationship contains the join column.OneToMany
: This specifies a one-to-many relationship between objects.
...