The API could be something like this:
Query.sql
SELECT * FROM user LEFT JOIN post ON user.id = post.id
Application.ts const results = await Query()
const nested = nest(results, {
parentFields: ['userId', 'name'],
childFields: ['postId', 'title'],
childName: 'posts'
)
If you wanted, you wouldn't really have to specify child fields, since they'd just whatever wasn't a parent field. It'd take a bit more work to get it to do multiple levels of nesting, but after a point it doesn't make sense to write queries that return so much duplicate data anyway.