1

For example I have a code like this:

conn.query('INSERT INTO events_log SET ?', [record]);

If there is an error, the library just displays an error itself, without the query was made by the library. Is it possible to see it?

P.S. I mean the query should look something like INSERT INTO events_log SET name = 'va\'lue' and example of the default error without this query is:

Error: Data too long for column 'ip' at row 1
    at PromiseConnection.query (/Users/node_modules/mysql2/promise.js:92:22)
    at /Users/server.js:195:9
    at processTicksAndRejections (node:internal/process/task_queues:93:5) {
  code: 'ER_DATA_TOO_LONG',
  errno: 1406,
  sqlState: '22001',
  sqlMessage: "Data too long for column 'ip' at row 1"
}
Eugene
  • 905
  • 1
  • 10
  • 22

1 Answers1

1

Adding debug: true to createConnection or createPool will show the assembled query:

mysql.createConnection({debug: true});
Eugene
  • 905
  • 1
  • 10
  • 22