Select Entry in db with relational tables
Hi, i'm using this request to get a store corresponding to the cuid, an di want to get also all his related categories from store_categories tabe
but it returns multiple times the store object for eact category.
i would like to have instead
where stores_categories are the categrories ids
17 Replies
This is the perfect use case for the relational query API
Drizzle Queries - DrizzleORM
Drizzle ORM | %s
hi, i tried like that but should i create a new db connection in my server component where i already have a db connection on a db/index.js
because when i tried this, i got errors
No need for a new connection.
If you get errors when attempting to use the relational api, it's most likely because you're not passing the schema to the DB object, or not passing it properly
Just follow the instructions in the docs
i try to follow the docs, but if i have my db connection withour passing schema in it inside a index.ts file for main db connection, i have to create a new one inside this file where i whant to get this formated data
by the way, this is my connection file, how should i pass my schemas into the connection while there is multiple schemas files
Well, either that or just aggregate the results to the shape you'd like it to be.
There is an example in the docs: https://orm.drizzle.team/docs/joins#aggregating-results
Joins [SQL] - DrizzleORM
Drizzle ORM | %s
well than you for this method !
two options, either import them each and create a schema object with all the tables and relations from all your schemas, or create an
index.ts
in the folder where all your schemas are and export from there all your schemasJoins [SQL] - DrizzleORM
Drizzle ORM | %s
like that ?
and the i can import * from index.ts
That's one way, yep
There is also an shorter syntax: `export {carts} from "./carts";
damn, okay, doing like this made me an error,
sorry it's in french
so i will stay with your first tips
hie ! do you know why it still give me this error ?