Updating in the database

Now let’s load a single photo from the database, update it and save it:

  1. import {createConnection} from "typeorm";
  2. import {Photo} from "./entity/Photo";
  3. createConnection(/*...*/).then(async connection => {
  4. /*...*/
  5. let photoToUpdate = await photoRepository.findOne(1);
  6. photoToUpdate.name = "Me, my friends and polar bears";
  7. await photoRepository.save(photoToUpdate);
  8. }).catch(error => console.log(error));

Now photo with id = 1 will be updated in the database.