在数据库中更新

在数据库中更新

让我们从数据库加载出 photo,更新并保存到数据库:

import { createConnection } from "typeorm";
import { Photo } from "./entity/Photo";

createConnection(/*...*/)
  .then(async connection => {
    /*...*/
    let photoToUpdate = await photoRepository.findOne(1);
    photoToUpdate.name = "Me, my friends and polar bears";
    await photoRepository.save(photoToUpdate);
  })
  .catch(error => console.log(error));

这个id = 1的 photo 在数据库中就成功更新了。