Does PlanetScale Work With Drizzle ORM?
PlanetScale and Drizzle ORM work seamlessly together—Drizzle has native PlanetScale support with proper MySQL protocol handling and connection pooling.
Quick Facts
How PlanetScale Works With Drizzle ORM
PlanetScale and Drizzle ORM integrate beautifully because Drizzle treats PlanetScale as a standard MySQL-compatible database with first-class support for its connection model. You connect via PlanetScale's connection string (which uses the `mysql2` protocol), and Drizzle handles schema definitions, migrations, and queries through its type-safe API. The real strength here is that PlanetScale's branching and revert capabilities pair naturally with Drizzle's migration system—you can test schema changes on branches before deploying to production. Drizzle's lightweight nature keeps bundle size minimal, which matters for serverless functions that query PlanetScale. The developer experience is straightforward: define your schema in TypeScript, generate migrations, push to PlanetScale, and write queries with full type inference. No special configuration needed beyond your connection string.
Best Use Cases
Quick Setup
npm install drizzle-orm mysql2 dotenvimport { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';
import { text, int, mysqlTable, timestamp } from 'drizzle-orm/mysql-core';
const connection = await mysql.createConnection(process.env.DATABASE_URL);
export const db = drizzle(connection);
export const users = mysqlTable('users', {
id: int().primaryKey().autoincrement(),
email: text().notNull(),
createdAt: timestamp().defaultNow(),
});
const newUser = await db.insert(users).values({ email: 'test@example.com' });
const allUsers = await db.select().from(users);Known Issues & Gotchas
PlanetScale enforces FOREIGN KEY constraints differently; some Drizzle relations may need adjustment
Fix: Use PlanetScale's implicit foreign key mode or explicitly set `onDelete: 'cascade'` in Drizzle relations. Test on a branch first.
Connection pooling through PlanetScale's proxy can timeout with long-running queries in serverless
Fix: Keep queries under 10 seconds, use connection pooling wisely, or implement query timeouts in Drizzle.
Drizzle's push command doesn't support PlanetScale branching directly—requires manual branch selection
Fix: Use PlanetScale CLI to switch branches, then run Drizzle migrations manually or script it.
Alternatives
- •Prisma + PlanetScale (heavier ORM, more features, larger bundle)
- •Kysely + PlanetScale (more SQL-focused, less hand-holding than Drizzle)
- •Raw mysql2 driver + custom query builder (maximum control, no type safety)
Resources
Related Compatibility Guides
Explore more compatibility guides