首页 > 解决方案 > 在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并检查两个表结果是否都有数据然后更新表。

标签: node.jspostgresql

解决方案


推荐阅读