Smart way to prepare data for frontend
As you can imagine, query returns aren't exacly pretty, and they'll have rows for each value that matches.
For example, let's say you want to grab posts and comments. On your select, you'd have a row (or in drizzle case, an object for each row) for each post and comment. something like
Is there a way (without scripting on the js side), to map certain keys to a schema you want to have? In this scenario I'd like to have something like
This is just a simple example, let me know if my explanation wasn't clear enough.
8 Replies
use the query api with relations, whcih will give you a nested data structure?
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Managed to completely skip that doc, only checked the select one. Yea this should do everything I want much appreciated
@francis reckon there's a way to fix
It's caused by what's inside the where
Reckon that it can't infer where jobs_table comes from because it's nested inside another db request? If not is there a way to add a join and use the where logic onthe query?
Is this related to the subqueries inside query?
no idea
I don't believe you can mix the query interface and where conditions on joined tables though
so queries wouldn't work for in my use case? that sucks
I dunno if they would. A potential option is to select a list of ids, then use that as an
inArray
input in your query, but it's not idealyea thats really not ideal, goona make another thread for that hopefully theres an answer