【问题标题】:Cannot use a pool after calling end on the pool TypeORM queryBuilder在池 TypeORM queryBuilder 上调用 end 后无法使用池
【发布时间】:2018-11-21 20:25:31
【问题描述】:

我正在使用 TypeORM 查询构建器尝试一些东西。但是在运行下面显示的代码后,我不断收到错误

(node:25699) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: Cannot use a pool after calling end on the pool

如果我首先添加user 关系或location 关系很重要,因为首先添加的关系会按预期添加为关系。之后的那个不断抛出错误。

userIds.forEach(async (userId, i) => {
  await getConnection()
    .createQueryBuilder()
    .relation(Pin, "user")
    .of(pinIds[i])
    .set(userId);

  await getConnection()
    .createQueryBuilder()
    .relation(Pin, "location")
    .of(pinIds[i])
    .set(locationIds[i]);
});

【问题讨论】:

    标签: query-builder typeorm


    【解决方案1】:

    我通过只创建一次连接并与该连接建立关系来解决问题。

    const connection = await getConnection();
    userIds.forEach(async (userId, i) => {
      connection
        .createQueryBuilder()
        .relation(Pin, "user")
        .of(pinIds[i])
        .set(userId);
    
      connection
        .createQueryBuilder()
        .relation(Pin, "location")
        .of(pinIds[i])
        .set(locationIds[i]);
    });
    

    【讨论】:

      猜你喜欢
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 2020-05-28
      相关资源
      最近更新 更多