Node.js/MySQL: Printing actual query in error log in node.js

前端 未结 2 594
闹比i
闹比i 2020-12-24 08:20

I have some Node.js code that tries to update a database in something like the following:

connection.query(command, function(err,rows) {
        if (err){
           


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 09:12

    If @Sridhar answer doesn't work for you, probably because you are using promise API which doesn't yet return the SQL query, you can use:

    const sql = connection.format("SELECT * FROM table WHERE foo = ?", ["bar"]);
    console.log(sql);
    const [rows] = await connection.query(sql);
    

    Documentation: https://github.com/mysqljs/mysql#preparing-queries

提交回复
热议问题