在池 TypeORM queryBuilder 上调用结束后无法使用池
Cannot use a pool after calling end on the pool TypeORM queryBuilder
我正在尝试使用 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]);
});
我通过只创建一次连接并与该连接建立关系解决了这个问题。
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]);
});
我正在尝试使用 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]);
});
我通过只创建一次连接并与该连接建立关系解决了这个问题。
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]);
});