results
contains the rows returned as an array. Since you're using SELECT COUNT(message)
, you're querying for the count of messages, which returns one row. This one row contains the result, which is an object of shape { total: 4 }
- where the total
comes from the as total
part of your SQL query.
To get the actual result, check that results.length > 0
and then you can access results[0].total
:
if (results.length > 0) {
console.log('Total:', results[0].total)
} else {
throw new Error('No results returned from query!')
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…