Fork me on GitHub
#sql
<
2022-02-22
>
Casey15:02:28

Are there any helper functions for reshaping a SELECT + JOIN query to nest the joined columns under a key at the root? For example, given a Pet with a single Owner, we have a select on Pet select * from pet inner join owner on owner.id = pet.owner_id, and I'd like to reshape the flat map returned by the query into a map such as { :pet/id 1 :pet/owner { :owner/id 1 :owner/name "Alice" } } I know this isn't next.jdbc's core area, but with all the other little helpers I thought there might be such a fn.

seancorfield16:02:03

@ramblurr Such a thing would always be very domain-specific although I think a few people have written functions to coalesce result sets based on keys/namespaces -- but 1:1 and 1:many look pretty different and you can't deduce that from the shape of the data in general so those relationships have to be "hinted" somehow through parameters.

Casey17:02:49

fair enough!

seancorfield17:02:30

The request comes up from time to time and I've given it some thought. I'll open an issue to track it because I think I might have enough examples in mind now to figure out something that would probably cover most cases (covering 100% is likely to be hard). https://github.com/seancorfield/next-jdbc/issues/201