Removing from the database

Now let’s remove our photo from the database:

  1. import {createConnection} from "typeorm";
  2. import {Photo} from "./entity/Photo";
  3. createConnection(/*...*/).then(async connection => {
  4. /*...*/
  5. let photoToRemove = await photoRepository.findOne(1);
  6. await photoRepository.remove(photoToRemove);
  7. }).catch(error => console.log(error));

Now photo with id = 1 will be removed from the database.