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
🇨🇭 Marko Bolliger <cannap>
i use this import { drizzle } from 'drizzle-orm/planetscale-serverless';
Jumaron
JumaronOP17mo ago
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
Ahmed
Ahmed17mo ago
I don't think mode: "planetscale is required. I'm using relation queries with planetscale serverless driver. Could you share your setup file ?
Jumaron
JumaronOP17mo ago
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
Ahmed
Ahmed17mo ago
My situation is just like yours. I moved from prisma to drizzle and I can't go back. Good luck!
Jumaron
JumaronOP17mo ago
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
cody
cody17mo ago
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
Jumaron
JumaronOP17mo ago
Exactly, sadly there is no way that we edit the Docs so i think i will do an issue for that
Asseater Peter
Asseater Peter17mo ago
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!
Jumaron
JumaronOP17mo ago
Yes your right i did already transfer yesterday/today mornign succesfully ! 🙂 I see they have there own repo for that thanks!
titongo
titongo15mo ago
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 PlanetScale
So 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
Angelelz
Angelelz15mo ago
Relational queries are available for planetscale Just pass mode: "planetscale" to object yo pass to drizzle along with your schema
titongo
titongo15mo ago
Oh alright Thanks
kelbs
kelbs13mo ago
@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:
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { connect } from "@planetscale/database";

// create the connection
const connection = connect({
host: process.env["DATABASE_HOST"],
username: process.env["DATABASE_USERNAME"],
password: process.env["DATABASE_PASSWORD"],
});

const db = drizzle(connection);
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { connect } from "@planetscale/database";

// create the connection
const connection = connect({
host: process.env["DATABASE_HOST"],
username: process.env["DATABASE_USERNAME"],
password: process.env["DATABASE_PASSWORD"],
});

const db = drizzle(connection);
Angelelz
Angelelz13mo ago
You pass your schema and the mode if you plan to use the relational query builder
kelbs
kelbs13mo ago
@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
Angelelz
Angelelz13mo ago
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.
Angelelz
Angelelz13mo ago
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
kelbs
kelbs13mo ago
I also get this type error when trying to add mode:
typescript: Argument of type '{ schema: typeof schema; mode: string; }' is not assignable to parameter of type 'DrizzleConfig<typeof import("<project>/src/lib/server/schema")>'.
Object literal may only specify known properties, and 'mode' does not exist in type 'DrizzleConfig<typeof import("<project>/src/lib/server/schema")>'. [2345]
typescript: Argument of type '{ schema: typeof schema; mode: string; }' is not assignable to parameter of type 'DrizzleConfig<typeof import("<project>/src/lib/server/schema")>'.
Object literal may only specify known properties, and 'mode' does not exist in type 'DrizzleConfig<typeof import("<project>/src/lib/server/schema")>'. [2345]
Angelelz
Angelelz13mo ago
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
kelbs
kelbs13mo ago
Thanks! Did you look at drizzle code to figure it out? In that case I think the docs are a bit misleading
Angelelz
Angelelz13mo ago
Yes, I did. I think I was just dumb. It's kinda clear. the docs say when using the mysql2 driver
Angelelz
Angelelz13mo ago
Drizzle Queries - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server