如何在控制台上的节点js上打印实际正在查询的查询
嗨,我正在尝试以下代码
userwallet.post('/api/user/wallet/create',verifyToken,(req,res)=>{
jwt.verify(req.token,'secretkey',(err,authData)=>{
if(err){
console.log(err)
return res.sendStatus('403');
}else{
mysqlConnection.query("INSERT into user_wallets(uuid,user_uuid,balance,status,created_at,updated_at) VALUES(?,?,?,?,?,?)",[uuid(),authData.id,0,'ACTIVE',new Date(),0],(err,rows,fields)=>{
if(!err)
return res.json({
message:"Successfull",
added:rows,
authData
});
console.log('Wallet creation error:',err)
return res.sendStatus('403');
});
}
});
});
在远程计算机上执行此代码有些麻烦,因为它不是查询的,所以我试图将查询放在控制台上,而我正在通过这个无用的答案
NodeJS - how can get mysql result with executed query?
有什么建议吗?用于故障排除
回答如下:您需要将connection.query分配给变量,例如查询,然后可以通过query.sql获取sql。 For more detail
var post = {id: 1, title: 'Hello WORLD'};
var query = connection.query('INSERT INTO TABLENAME SET ?', post, function(err,
result) {
// SOMETHING
});
//HERE YOU CAN GET QUERY
console.log(query.sql);