How do I check with nodejs if a table is out of records?

Asked

Viewed 453 times

2

Well, I intend to check a table with nodejs, to see if it is without records.

How can I do this in a way that makes no mistake, with nodejs?

Thank you.

1 answer

2


Checks 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!');
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.