While setting up a nodejs server with a mariadb database, I found this:
While the recommended method is to use the question mark placeholder, you can alternatively allow named placeholders by setting this query option. Values given in the query must contain keys corresponding to the placeholder names.
This seems odd to me as the named placeholders seem more readable and the ability to use each instance multiple times makes it more flexible. For example, consider this with the ?
method:
connection.query(
"INSERT INTO t VALUES (?, ?, ?)",
[1,"Mike","5/12/1945"]
)
A named version could look like
connection.query(
{ namedPlaceholders: true,
"INSERT INTO t VALUES (:id, :name, :dob)" },
{ id: 1, name: "Mike", dob: "5/12/1945" }
)
It also seems much more likely for the data to be in an object format over an array anyway. So why recommend a less readable option? Why not make namedPlaceholders
default to true instead?