javascriptnode.jssqlitebetter-sqlite3

Sqlite COUNT returns `[object Statement]`


I have let usersin1 = sql.prepare("SELECT COUNT(*) FROM raid WHERE raid1 > 0");

using better-sqlite3 and what I'm getting from this is a [object Statement]. I don't understand why I'm getting it when I try to get the value of usersin1. All values are defined and I'm trying to get a number out of this.

Node.js


Solution

  • sql.prepare() returns a Statement object. You need to execute the statement to get the results.

    let stmt = sql.prepare("SELECT COUNT(*) count FROM raid WHERE raid1 > 0");
    let row = stmt.get();
    let usersin1 = row.count;