node.js - 为什么要发布 QueryRunner?
问题描述
我有一个看起来像这样的大型工作流程
@Transaction()
doAlotOfStuff(
@TransactionManager() txEntityManager: EntityManager
) {
const myEntity txEntityManager.getRepository(MyEntity).find(id);
doSomething(txEntityManager, myEntity);
doSomethingElse(txEntityManager, myEntity);
txEntityManager.getRepository(MyEntity).save(myEntity);
const data = txEntityManager.getRepository(AnotherEntity).find( /*some complex find conditions*/ )
doMoreStuff(txEntityManager, datat);
}
不幸的是,真正的功能过于复杂,无法在此处发布。但问题是,在运行该函数的过程中,QueryRunner
它会被释放,当它尝试运行更多查询时它会崩溃。我确保每个查询都使用txEntityManager
. 我不明白为什么它一直被释放。我调试并发现使用该find
函数的查询正在释放QueryRunner
.
查找功能如下所示
public async getHistoricalCustomerOrders(entityManager: EntityManager, superOrder: SuperOrder, customerIds: string[]) : Promise<CustomerOrder[]> {
return await entityManager.find(CustomerOrder, {
where: qb => {
qb.where({
customerId: In(customerIds),
})
.andWhere('"CustomerOrder__order__superOrder"."start_date_period" > :startDate', {
startDate: sub(superOrder.startDatePeriod, { years: 1 }),
})
.andWhere('"CustomerOrder__order__superOrder"."start_date_period" < :endDate', {
endDate: superOrder.startDatePeriod,
});
},
relations: [
'some relations'
],
});
解决方案
推荐阅读
- java - 即使未定义 `setMaxResults`,JPA 也会限制 `queryResultList`
- flutter - 运行颤振应用程序时出错
- c# - 从openGL控件的顶部和底部切割特定区域时投影不起作用
- eclipse-rcp - 获取 Observable 的属性
- sharepoint-2013 - 从 SharePoint 设计器 2013 中的另一个列表创建新项目时如何更新字段
- java - 为什么不能在 Eclipse 中将输出文件夹设置为 WEB-INF/classes
- postgresql - 无法使用 pgAdmin 读取 CSV 文件,
- javascript - 使用 javascript 显示图像时只显示一张图像
- android - 为什么在 google play 暂停我的应用后 Admob 广告没有显示?
- azure - Azure 资源删除锁可防止删除资源上的角色分配