Mapping Query Builder Results to Nested Objects in Drizzle

I'm transitioning to Drizzle ORM from a NestJS-TypeORM background : TypeORM: Both the repository and query builder return similar structured results, making it easy to work with joined data. Drizzle: db.query() returns nicely structured nested data (e.g., users and their posts grouped together). Query Builder (db.select()) returns raw, flattened data requiring additional processing to achieve a similar structure. Example: db.query result: [{ "id": 10, "name": "Dan", "posts": [ { "id": 1, "content": "SQL is awesome", "authorId": 10 }, { "id": 2, "content": "But check relational queries", "authorId": 10 } ] }] Query Builder result: const result: { user: { id: number; name: string }; pets: { id: number; name: string; ownerId: number } | null; }[] = await db .select() .from(users) .leftJoin(pets, eq(users.id, pets.ownerId)); I'm looking for a mechanism or best practice to map Query Builder results into a nested format (similar to db.query) so that my API responses are consistent and clients don’t need to check different formats. Any advice, patterns, or libraries you'd recommend for this? How do you handle this in your Drizzle-based projects? Thanks in advance!
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server