Search code examples
node.jsexpressloggingmariadbmariasql

How to see a log of query string in (Maria SQL + Node.js)?


I'm using Node.js, Express and Maria.

q = `SELECT * FROM TEST
     WHERE id=?`;

maria.query(q,[id],function (err, rows) {
               if (err) throw err;
               //I want to see completed query string.
            });

Finally, I want to get a completed query string.

But now, I've seen SELECT * FROM TEST WHERE id=? in my log file.

e.g)
If id == 3

console.log(something);

vi ...../my_node.log

: SELECT * FROM TEST WHERE id=3


Solution

  • Most database drivers use prepared statements to execute parameterized queries. This means that the complete query is never constructed at the client end and only the values are sent over to the database. The database itself constructs the query.

    I believe you have to construct it yourself unless the driver offers a method for generating the query string.