2023 年 2 月 3 日

自己看自己抄,不解釋了,因為我也不會


var sql = require("./Class/mssql.js")


let sqlA = new sql();




//result=Query(strSQL);

//result = queryDb(strSQL).then((data) => { return data });


function funcB(int) {
    return new Promise(function (resolve, reject) {
        console.log(int);
    });
}




const queryPromise1 = () => {
    return new Promise((resolve, reject) => {
        sqlA.Query("SELECT TOP 1 * FROM FTP_UserAccount", (error, results) => {
            if (error) {
                return reject(error);
            }
            return resolve(results);
        });
    });
};

const queryPromise2 = () => {
    return new Promise((resolve, reject) => {
        sqlA.Query("SELECT TOP 1 * FROM FTP_Error_Log", (error, results) => {
            if (error) {
                return reject(error);
            }
            return resolve(results);
        });
    });
};

const queryPromise3 = () => {
    return new Promise((resolve, reject) => {
        sqlA.Query("SELECT TOP 1 * FROM code_d", (error, results) => {
            if (error) {
                return reject(error);
            }
            return resolve(results);
        });
    });
};


async function sequentialQueries() {
    funcB(1);
    try {
        const resultA = await queryPromise1();
        const resultB = await queryPromise2();
        const resultC = await queryPromise3();

        // here you can do something with the three results

        console.log(resultA);
        console.log(resultB);
        console.log(resultC);
    } catch (error) {
        console.log(error)
    }
    funcB(2);
}



sequentialQueries();

參考來源