Using async/await syntax

Let’s take advantage of the latest ES8 (ES2017) features and use async/await syntax instead:

  1. import {createConnection} from "typeorm";
  2. import {Photo} from "./entity/Photo";
  3. createConnection(/*...*/).then(async connection => {
  4. let photo = new Photo();
  5. photo.name = "Me and Bears";
  6. photo.description = "I am near polar bears";
  7. photo.filename = "photo-with-bears.jpg";
  8. photo.views = 1;
  9. photo.isPublished = true;
  10. await connection.manager.save(photo);
  11. console.log("Photo has been saved");
  12. }).catch(error => console.log(error));