mariadb-corporation / mariadb-connector-nodejs

MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
GNU Lesser General Public License v2.1
366 stars 91 forks source link

Update query with '?' #191

Closed karolpiernikarz closed 1 year ago

karolpiernikarz commented 2 years ago

I have a question regarding the following UPDATE statement. Is this actually possible? If not, can you please suggest a solution?

await sqlConnection.query('UPDATE MyTable SET ? WHERE id='${id}'', updateObject);

rusher commented 2 years ago

question mark correspond to parameters. if you need some part of query to be build from variables, better to use Template literals, like:

await sqlConnection.query(UPDATE MyTable SET ${sqlConnection.escapeId(updateObject)} WHERE id=?, [id]);

this way, updateObject is properly escaped, and parameter is at his place