Drizzle ORM - Planetscale/mysql many to many

648 Views Asked by At

I'm learning mysql coming from mongoose.

I'm using the t3 stack with drizzle and planet scale and I'm trying to get my head around creating a schema with a many to many relationships.

Tables needed:

  1. credits

  2. categories

  3. Junction table credits_categories

Can anyone show me how they'd set this schema up in Drizzle ORM and query it in the many to many config? I'm struggling to get the hang of it.

Thank you!

Haven't tried anything yet on my own.

1

There are 1 best solutions below

0
On

My suggestion would be to check out the Drizzle docs.

https://orm.drizzle.team/docs/rqb#many-to-many

The example is for postgres, but you should be able to change the import to use the mysql specific table and columns. Something like this:

import { mysqlTable, serial, text, integer, boolean, primaryKey } from 'drizzle-orm/mysql-core';
import { relations } from 'drizzle-orm';

Then adjust the example to fit your table definitions and you should be good to go.