I am making some Node.js backend code that will read some data from a database, and I need to get the results from the database query, but I don't know how to do that, or if there even is a way to do it. Here is my code that queries:
db.query(sql, (err, rows) => {
if (err) throw err;
console.log();
return rows[0]['COUNT(*)'];
})
Also, I am using the MySQL library, and this is the whole function:
LengthOfTable: function (tableName = string) {
sql = `SELECT COUNT(*) from ${tableName}`;
db.query(sql, (err, rows) => {
if (err) throw err;
console.log();
return rows[0]['COUNT(*)'];
})
}