node.js 中的承诺发生错误,希望将此作为承诺的连接并修复

Error occurs on promise in node.js looking to make this a promised connection and fix

await conn.query("SELECT ID, idle_timer, action, combat FROM users WHERE idle_timer >= 1 ORDER BY ID ASC", async function(err, results) {
    }

错误发生在 await conn.query("SELECT ID, idle_timer, action, combat FROM users WHERE idle_timer >= 1 ORDER BY ID ASC", async函数(错误,结果){

希望将其转换为承诺?

您可以使用 MySQL 来获取数据

回调模式

conn.query("SELECT ID, idle_timer, action, combat FROM users WHERE idle_timer >= 1 ORDER BY ID ASC", function(err, results) {...})

或Promise模式

conn.query("SELECT ID, idle_timer, action, combat FROM users WHERE idle_timer >= 1 ORDER BY ID ASC").then(results => { ... })

或者可能在 Promise 模式下使用 Await/Async 语法糖

const result = await conn.query("SELECT ID, idle_timer, action, combat FROM users WHERE idle_timer >= 1 ORDER BY ID ASC")
    //...
    const results = await conn.query("SELECT ID, idle_timer, action, combat FROM users WHERE idle_timer >= 1 ORDER BY ID ASC");
    await conn.release();

    for (let i = 0; i < results.length; i++) {
        //... processing results
    }

如果您是 async/await 的新手,请阅读 promises,至少 https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/async_function