Planetscale Serverless for Relational queries
Currently it is only supported to use mysql2 for using the Relational queries feature with Planetscale, with that the advantage of using the serverless driver with planetscale vanishes.
Would it be possible to implement the planetscale serverless driver instead of mysql2?
Thanks for any answer 🙂
Edit: Yes you can use it with PlanetScale driverless just like normel
23 Replies
i use this import { drizzle } from 'drizzle-orm/planetscale-serverless';
I know what you mean but the problem comes when i try to do this:
const db = drizzle(connection, { schema, mode: 'planetscale' });
Settings the schema Mode in Relational Queries to planetscale is sadly not working with the planetscale serverless import
I don't think
mode: "planetscale
is required.
I'm using relation queries with planetscale serverless driver.
Could you share your setup file ?I just saw it in one of the Github Merged Pull requests that planetscale serverless does nativly support it 5mins ago i'am right now switching again from Prisma + kysely to Drizzle will report back when i get results
Still thanks that you answered if i did not see that i would have went insane
My situation is just like yours. I moved from prisma to drizzle and I can't go back.
Good luck!
Thanks 👍🏼
Done works Great! thanks again, but it should be really declared in the Docs that you can use it since it is not that obvious in the docs since they state that you need to change the mode to schema=planetscale
I was confused by that as well. I think the intention was to show how to set it up if you're using mysql2 with the planetscale driver - not to imply that you have to use mysql2 to get relational queries to work with the planetscale driver
Exactly, sadly there is no way that we edit the Docs so i think i will do an issue for that
I'm 100% certain that this is just not true.
Just set up the ORM for PlanetScale like the docs say and then use relational queries. Should work perfectly fine.
You can! The Drizzle Team have the docs site repo on GitHub as well!
Yes your right i did already transfer yesterday/today mornign succesfully ! 🙂
I see they have there own repo for that thanks!
Hey so kind of related, I found this in the docs:
Drizzle relational queries always generate exactly one SQL statement to run on the database and it has certain caveats. To have best in class support for every database out there we've introduced modes.
Drizzle relational queries use lateral joins of subqueries under the hood and for now PlanetScale does not support them.And later this is said in the same page:
What this means is relations and foreign keys can be used together, but they are not dependent on each other. You can define relations without using foreign keys (and vice versa), which allows them to be used with databases that do not support foreign keys, like PlanetScaleSo I'm not sure I understand, are relations (the drizzle feature) not a thing on planetscale? Because the first fragment I quoted says they aren't Thanks! (sorry about this) bump
Relational queries are available for planetscale
Just pass
mode: "planetscale"
to object yo pass to drizzle along with your schemaOh alright
Thanks
@Angelelz is it still required to pass
mode: "planetscale"
to drizzle?
Based on this page (https://orm.drizzle.team/docs/quick-mysql/planetscale) the planetscale setup code is this:
You pass your schema and the mode if you plan to use the relational query builder
@Angelelz what about the rest of the thread saying its not required to pass mode and works without it? Plus my own testing in local dev using relational queries without it? Seems like the following is true, but the docs don't make it super clear as evidenced by all the confusion in this thread
1. If using planetscale serverless driver, don't need to pass mode
2. If using mysql2 driver, need to pass mode
I don't use the serverless driver but it is my understanding that whenever you are using planetscale you should define the mode. Here is the relevant part in the docs https://orm.drizzle.team/docs/rqb#modes
Drizzle Queries - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
I might be wrong, but from my understanding of the codebase you in fact need to pass the mode whenever you are using MySQL dialect, to use subqueries instead of lateral joins to construct the relational queries
I also get this type error when trying to add mode:
I'll investigate this as soon as I can.
Yep, you're totally right. When you're using the planetscale driver you don't need to pass in the mode
Thanks! Did you look at drizzle code to figure it out? In that case I think the docs are a bit misleading
Yes, I did.
I think I was just dumb. It's kinda clear. the docs say when using the mysql2 driver
Drizzle Queries - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.