Well, I want to check a table with nodejs to see if it has no records.
How can I do this so that it does not give error with nodejs?
Thank you.
Well, I want to check a table with nodejs to see if it has no records.
How can I do this so that it does not give error with nodejs?
Thank you.
Check the .length
of the result:
db.query('SELECT * from tabela', (err, res) => {
console.log(err, res, res.length); // deve dar null, [], 0
if (res.length == 0){
console.log('A tabela está vazia!');
}
});