'How to access query result with the selection as object name

I have made a query on a data and it returns a result: [ RowDataPacket { 'COUNT(t.id)': 2 } ]

How can I access it like the count number? I have tried result.COUNT(t.id) but it isn't worked.



Solution 1:[1]

The way the object is named, you need to access it like so:

result[0]["COUNT(t.id)"]

I would rather name the columns explicitly by using aliases in the query:

select count(t.id) as count_of_id
from ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Salman A