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
Angelelz
Angelelz4w ago
Yeah, that's a great usecase for the relational query builder
Angelelz
Angelelz4w ago
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Pinea
PineaOP3w ago
When should you use query vs select?
Angelelz
Angelelz3w ago
They solve similar problems with slightly different syntax, so it's entirely up to you
Pinea
PineaOP3w ago
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)
Angelelz
Angelelz3w ago
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
Want results from more Discord servers?
Add your server