How do I get the number of rows from a table?

1115 views node.js
-1

I am simply trying to get the number of rows in a table to update a counter. I've tried:

getRowCount(callback) {
    this.db.all(`SELECT COUNT(*) FROM pk_patients`, (err, rows) => {
        if (err) {
            console.log(err);
        } else {
            callback(rows[0].count);
        }
    });
}

I just get undefined. The table does have data in it.

answered question

1 Answer

11

Change SELECT COUNT(*) FROM pk_patients

to SELECT COUNT(*) as 'count' FROM pk_patients

posted this

Have an answer?

JD

Please login first before posting an answer.