I want count total comment of post and this is my query:
let totalComment = await strapi.connections.default
.raw(`SELECT (COUNT(comments.post) + COUNT(DISTINCT replies.comment)) As Total_Count
FROM comments
LEFT JOIN comments AS replies ON replies.comment = comments.id
WHERE comments.post = ${id}`);
And result is:
{
command: 'SELECT',
rowCount: 1,
oid: null,
rows: [ { total_count: '7' } ],
fields: [
Field {
name: 'total_count',
tableID: 0,
columnID: 0,
dataTypeID: 20,
dataTypeSize: 8,
dataTypeModifier: -1,
format: 'text'
}
],
_parsers: [ [Function: parseBigInteger] ],
_types: TypeOverrides {
_types: {
getTypeParser: [Function: getTypeParser],
setTypeParser: [Function: setTypeParser],
arrayParser: [Object],
builtins: [Object]
},
text: {},
binary: {}
},
RowCtor: null,
rowAsArray: false
}
If i want get count i must do:
let totalCount = result.rows[0].total_count.
It is complex, so i want return only total_count field in result:
let totalCount = result.rows
How can do that?