1
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 *
Aidan
  • 413
  • 3
  • 22

2 Answers2

1

{ '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
Sridhar
  • 11,466
  • 5
  • 39
  • 43
0

I found the solution is

Object.values(rows);

It will return a length 1 array with just the number

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Object/values

Aidan
  • 413
  • 3
  • 22
  • This is a worse solution that Sridhar's because it is an array instead of just the count – Aidan Apr 15 '19 at 04:09