首页 > 解决方案 > 在 Async Await NodeJS 中包含 const 数组

问题描述

我需要在以下数组中使“异步等待”工作,以便可以执行其余代码。

listArray = [1520,1320,1560,5091] //dont move array
}).on("close", async () => {
    const codeFormat = await `array[${listArray.map((v) => `'${v}'`).reduce((r,v) => `${r},${v}`)}]`

    const first = await app.db.raw(`
        SELECT distinct t.code
            from table AS t
            where not exists (select 1 from unnest(${codeFormat}) el where t.code = el)
    `)
    const second = await app.db.raw(`
        select code
            from unnest(${codigosFormatadoArquivo}) code 
            where not exists (select 1 from tableName as t where t.code = code
    `)
    console.log('first.rows',first.rows)
    console.log('second.rows',second.rows)

    return resolve({dados, footer, header})
})`

目前的方式,它只是执行第二个“const segundo”查询,第一个不能执行。

标签: javascriptasynchronous

解决方案


推荐阅读