嗨,我想在lambda(node)函数中使用mysql的begintransactio或transactio提交回滚功能。我尝试了mysql包的基本结构,但在lambda中似乎不起作用
const mysql = require('mysql');
exports.handler = async (event) => {
const con = mysql.createConnection(
{
host: "host",
user: "user",
password: "*****",
database: "db"
}
);
con.beginTransaction(
function (err) {
con.query(
"query goes here",
function (err, status) {
if (err) {
con.rollback();
con.end();
return err;
} else {
con.commit();
con.end();
return true;
}
})
});
}
1条答案
按热度按时间798qvoo81#
抱歉,迟了答复。只需要指定begintransaction而不需要回调