Files
main.tsmain
What you'll learn
- Connect an application with TypeOrmModule.forRoot() and explain synchronize and autoLoadEntities
- Define an entity with @Entity, @PrimaryGeneratedColumn and @Column, and register it with forFeature so its repository is injectable
- Use a repository's find, findOneBy, save and delete, decide where a 404 comes from, and write an aggregate with the query builder
Press Run tests to start the app. Its log appears here.Graded endpoints
save() inserted the row and came back with the generated id and the column default
A second row, id 2
One query: COUNT and AVG through the query builder, as numbers
findOne found the row, save() updated it
find() with a where clause
Both rows, ordered by id
findOneBy returned null and the service turned it into a 404
delete() removed one row
delete() affected no rows, which the service reports as a 404
The aggregate reflects the table