首页 文章

在池TypeORM queryBuilder上调用end后无法使用池

提问于
浏览
0

我正在尝试使用TypeORM querybuilder的一些东西 . 但是在运行下面显示的代码后,我不断收到错误

(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]);
});

1 回答

  • 0

    我通过仅创建一次连接并与该连接 Build 关系来解决问题 .

    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]);
    });
    

相关问题