Hi came across this syntax in a node.js application, in which we are making a SELECT query to our postgres database.
app.get("/monsters/:id", (req, res, next) => {
let id = req.params.id;
pool.query(`SELECT * FROM monsters WHERE id = $1`, [id], (err, response) => {
if (err) return next(err);
console.log(response.rows);
res.send(response.rows);
})
});
I don't understand the follow the line:
pool.query(SELECT * FROM monsters WHERE id = $1
, [id], (err, response) => {
how does this kind of string literal work, where we have used $1 and passing an array?
Thank you