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

.
Menu