I can't find any note on this topic in the docs, I hope someone has a solution. I'm trying to escape my queryparameters, but I can' add an alias without breaking the query.
What I want to achieve:
SELECT order.name as orderName, customer.name as customerName FROM order LEFT JOIN customer ON order.customerID = customer.id
What I'm doing:
let order = 'order.name as orderName';
let customer = 'customer.name as customerName';
let str = "SELECT ?? FROM order ...."
connection.query(str, [[order,customer]], function(err,res,fields){...}
What I get:
SELECT 'order'.'name as orderName, customer'.'name as customerName' FROM order ...
Obviously this won't work. How can I pass an alias to an escaped param??
edit: If I use only one '?' I get the following query, which won't work as well:
SELECT 'order.name as orderName', 'customer.name as customerName' FROM order
Thanks a lot!
The reason I'm not writing the query at once, are the confusing line breaks in javascript ('xyz, ' + ' abcd, ' + .. if I miss one blank space at the end of a line, js will concat them). I want those long queries to be as readable as possible. splitting the columnnames in single var's seems to be the only way. Or has someone a good approach for this?