The return problem of ES6 Asynchronous function

A member function in the

class
function queries the data and returns the result set


in

class DB.
async Query (strSql)

{
    await this._conpool.request()
    .query(strSql, (err, result) => {
        console.dir(result.recordset);    //
        return result.recordset;
    });
} 

call
let db = new DB ();

db.Query2 ("select * from sc_Product"). Then (ret = > {

)
    console.dir(ret);
    res.json(ret);
}); 

has not been able to get the correct data, the previous print shows that the Query function query is correct.
ask for advice!

Apr.09,2021

encapsulated in promise, your way of writing is a bit awkward, (by the way, async is ES7)

async function(){
    let db = new DB();
    try{
        let ret =await db.Query('select * from sc_Product');
        console.dir(ret);
        res.json(ret);
    }catch(e){
        //error
    }
}
    
await what is used for wait is a promise (if it is not promise, the result will be returned directly), and the return value of an async function is actually an promise, so they form a set of syntax for writing asynchronous code in Synchronize way.
any asynchronous operation must be encapsulated in promise before the syntax sugar async/await can be used.

from your first function, you can see that you don't quite understand the syntax of promise. It is suggested to find a relevant blog to study

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f44a-2c488.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f44a-2c488.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?