How to get the count of records? Here is my normal sql, trying to translate into drizzle

.select({
      id: comments.id,
      parentId: comments.parentId,
      // TODO countReplies: get the comment count where this id is listed as the parentId of other comments
      (
             SELECT COUNT(*)
             FROM comments AS childComments
             WHERE childComments.parentId = comments.id
           ) AS countReplies
    })
    .from(comments);
Was this page helpful?