node.js - 在nodejs中循环db查询承诺的结果
问题描述
嗨nodejs
,我有我正在使用的应用PostgreSQL
程序DB
。我在获取员工数据的方法中有以下内容
const result = await DBService.query(EmpQuery.getEmployeeId());
const empPromises = [];
for (const empAccount of result.rows) {
try {
const empId = empAccount.empid;
const QueryObj = new EmpQuery(empId);
empPromises.push(DBService.query(QueryObj.getCurrentEmployee())); // from employeeTable
empPromises.push(DBService.query(QueryObj.getEmployeeWithDept())); // from dept table.
} catch (error) {
logger.info(error);
}
}
const promiseresult = await Promise.all(empPromises);
我有两个查询结果promiseresult
。我想promiseresult
仅在两个查询结果都有数据时更新另一个表。如何循环promiseresult
并检查两个表结果是否都有数据然后更新表。
解决方案
推荐阅读
- wordpress - 单击帖子时的Wordpress重定向
- c# - JWT for ASP .NET Core - 每个用户的唯一密钥
- python - 如何组合不同列表中的元素
- postgresql - PostgresException:42703:关系“y”的列“x”不存在
- php - 我如何计算 PHP 中的总登录时间?
- python - tf.get_operations 实际返回什么?
- ios - 仅在布局 UIView 时发送数据源信息?
- uvm - 如何按UVM顺序访问变量
- java - 为 Jersey 资源提供 lambda 上下文
- asp.net-core-mvc - 从表单中获取所有值