Adding joins to objects
Just a short post with a "yes it's a thing" or "no do it manually"
Assuming I had a database with users and files, where each file has a user in the "owner" field, is it possible to select all users, but with a join which returns
[{ name: "...", files: [...] }]
6 Replies
Yeah, that's a great usecase for the relational query builder
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
When should you use query vs select?
They solve similar problems with slightly different syntax, so it's entirely up to you
So would it be possible to do this kind of output using .select()?
(As in, the format listed in the initial message)
I massively prefer the syntax with .from and .where etc. and was hoping there'd be a way to get that form
(I feel like the docs aren't super clear on the different kinds of joins too btw, it kind of just says they exist)
Yes, you can construct the same query and with array aggregation for the same output, although you might need to do some manual mapping
Drizzle select syntax is very similar to plain sql. The docs won’t teach you about sql. Although they’re trying to make it more beginner friendly