Replies: 1 comment 2 replies
-
I said bye-bye to ORMs long ago (not even sure I ever really said hello)... 😉 Look into PostgreSQL features for JSON which will allow you to return exactly the result you want Eg: select
name,
json_agg(p) as posts
from users u
left join lateral (
select
created_at,
title,
content
from posts
where user_id = u.user_id
) p on true |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Given that PostgreSQL has natural support for array and records, I would like to materialise one-to-many relationships in JS directly from the query result, without subsequent processing.
Let's say that an entity A owns multiple B entities. Normally, such data are brought in memory with a query like this:
The returned result set requires further processing to convert it to an array of A entities each carrying in a property the array of owned Bs 👎🏻
I'm interested in a query built along the lines of this:
Unfortunately, the database returns in column
bs
(no bullshit!) string literals of arrays of records, while I would like to be handed an actual JS array with actual JS objects as items. I suppose this can be done on the client side, since you also receive the result set metadata.What do you think (about saying bye-bye to suboptimal ORMs)❓
Beta Was this translation helpful? Give feedback.
All reactions