I am working with Nodejs and expressjs,Right now i am trying to execute select query , query is working successfully but i want two things
1) How to convert this query to "paramerized query" ?
2) Whenever i am trying to get "total rows" then i am getting "[object object] "
Here is my current code
static async addServiceDetail(shopId,serviceId,genderTypeId,price,serviceName)
{
const sql = `SELECT id from hc_servicesdetail WHERE shopId='${shopId}' AND serviceId='${serviceId}' AND genderTypeId='${genderTypeId}'`;
const [rows, fields] = await pool.execute(sql);
console.log('total rows are'+ rows); // getting [object object]
if(rows<1)
{
//further code
}
}
2
Answers
For printing the value that is contained inside results just use results.
You can pass parameters as an array to the
execute
call, then log the rows to the console:The output will look something like this: