Closed VadimZP closed 4 months ago
If those comments are at the root level it might be worth it to just use Prisma's findMany
. You could write something like this to get all the roots + 1 level of their children:
await prisma.node.findMany({
where: { OR: [
{ depth: { equals: 1 } },
{ depth: { equals: 2 } }]
}
})
Otherwise if you want to limit how many children you got back you might need to do findSiblings
and then findChildren
for each sibling with a take
argument. This operation can even be wrapped up in a $transaction
in case you were thinking of using Promise.all. (I'm suggesting because there used to some issues with Promise.all and SQLite: https://github.com/adamjkb/bark/pull/54/commits/740aecfad496deaf1a34cf699372b742428f899d)
Thank you!
Hello! I have a comments section and I request "root" comments with
findSiblings
.How can I get at least one or two children of each sibling? Reddit's comments section is a good example of what I am trying to achieve 🙂