I can see that node-mysql offers the ability to print the statement by providing query.sql, however when I try that with native promises, it returns undefined, e.g.:
connection.query('SELECT * FROM mytable WHERE id = 1')
.then(query => {
console.log(query.sql)
})
returns undefined. Am I missing anything?
Thank you!
at the moment this is not possible, promise api only gives you rows + fields
We could potentially return Query object as well so you would be able to do something like this
const [rows, fields, query] = await conn.query('select ? as test', [123]);
console.log(query.sql);
I think right now recommended way would be create string first and later use it:
const sql = conn.format('select 1 as test', [123]);
console.log(sql)
const [rows] = await conn.query(sql);
@sidorares
That's why I made this PR #555 a year ago.
This comment (EDIT 4 part) is exactly what you're talking about. Any plans to implement?
Most helpful comment
at the moment this is not possible, promise api only gives you rows + fields
We could potentially return Query object as well so you would be able to do something like this
I think right now recommended way would be create string first and later use it: