Persistence — Capstone: the shelter service · NestJS

Move the cats into a database without changing a single response, then add adoptions: a second table related to the first, and an adoption that marks the cat and records itself in one transaction, rolled back whole when a rule refuses it.

What you will learn

Read the theory for Persistence

All Capstone: the shelter service lessons

All NestJS courses

loading types…

What you'll learn

  • Replace an in-memory store with TypeORM repositories behind the same service, so the API does not change
  • Seed a fresh database when a module starts, with OnModuleInit
  • Relate two entities with @ManyToOne, typed with Relation<> so the files can import each other safely, and load the relation with every read
  • Make a multi-step change all or nothing with DataSource.transaction(), and prove the rollback by reading the data back