What's the recommended way to handle joins that aggregate results?
I'm currently converting a codebase that uses raw sql postgres queries over to drizzle, and have this query:
I was wondering what the recommended way of queries that aggregate joins using functions such as
JSON_AGG
or ARRAY_AGG
?4 Replies
One solution I came up with is this:
However this has the downside of not being strongly typed as the features column of the result is now type
unknown
.
Another way I can think of is just doing the joins normally and then using javascript to actual format it how I want.
Would appriciate peoples take on this!
bumpThe approach you're using is currently the best. Drizzle doesn't have JSON helpers at the moment so you have to create the types and map it in JS/TS
Thanks for letting me know! I had an obsession in the past with trying to write sql queries that got all the data and formatted it exactly how I needed it so I'm going to be writing a lot of data formatters, but still loving Drizzle haha 😄
Sounds good. JSON util functions are definitely on the roadmap, although no ETA for them as of yet