Search code examples
node.jssqlitebetter-sqlite3

Reading object returned from "SELECT COUNT(*) FROM table"


let rows = db.prepare("SELECT COUNT(*) FROM table").get();

Returns the object

{ 'COUNT(*)': 2 }

I am not sure how to read that as

console.log(rows.COUNT(*));

Returns

SyntaxError: Unexpected token *

Solution

  • { 'COUNT(*)': 2 }

    Since COUNT(*) is a key. You can access it directly by using Bracket notation

    console.log('No of rows ', row['COUNT(*)']); //logs 2