Does PlanetScale Work With TypeORM?
TypeORM works seamlessly with PlanetScale as a standard MySQL database, offering excellent developer experience with full ORM capabilities.
Quick Facts
How PlanetScale Works With TypeORM
TypeORM connects to PlanetScale through standard MySQL protocols, treating it like any other MySQL instance. You configure a TypeORM connection with PlanetScale's connection string (available in your dashboard), and all ORM features—migrations, relations, query builder, decorators—work identically. PlanetScale's serverless architecture and connection pooling layer (Vitess) are transparent to TypeORM; the driver handles everything automatically. The main advantage is that you get database branching for development workflows without modifying your TypeORM setup—branch creation and deletion happen at the database level, not the application level.
One consideration: PlanetScale enforces Foreign Key constraints more strictly in some configurations (depending on your plan), which can affect cascading deletes and certain migration patterns. TypeORM's migration system works perfectly, but you need to be aware of how PlanetScale's online DDL handles schema changes. The serverless/pay-per-request pricing model pairs well with TypeORM's connection pooling, reducing the risk of connection exhaustion.
Best Use Cases
Quick Setup
npm install typeorm mysql2import { DataSource } from 'typeorm';
import { User } from './entities/User';
const AppDataSource = new DataSource({
type: 'mysql',
host: process.env.DB_HOST,
port: 3306,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [User],
synchronize: false,
logging: false,
ssl: 'REQUIRED',
extra: {
waitForConnections: true,
connectionLimit: 5,
},
});
AppDataSource.initialize()
.then(() => console.log('Connected to PlanetScale'))
.catch((err) => console.error(err));Known Issues & Gotchas
Foreign key constraints may be disabled by default on some PlanetScale plans, causing TypeORM relation decorators to not enforce database-level constraints
Fix: Enable foreign key checks in PlanetScale settings or explicitly set relations with `onDelete` and `onUpdate` strategies in TypeORM decorators
Connection string authentication uses username:password@host format; PlanetScale requires the correct region-specific host to avoid latency
Fix: Always use PlanetScale's provided connection string from the dashboard; avoid hardcoding hostnames
TypeORM's connection pooling can conflict with PlanetScale's connection limits on smaller plans if you spawn multiple application instances
Fix: Configure TypeORM's `extra.waitForConnections` and lower `connectionLimit` for serverless environments, or upgrade to higher PlanetScale plan
Migrations using `RAW` SQL with PlanetScale-specific syntax may not work in local development if using a standard MySQL instance
Fix: Test migrations against a PlanetScale branch or use PlanetScale's local development tooling
Alternatives
- •Prisma + PlanetScale (more modern, slightly better DX for serverless)
- •Sequelize + PlanetScale (simpler ORM, less type safety)
- •Knex.js + PlanetScale (lightweight query builder, minimal abstraction)
Resources
Related Compatibility Guides
Explore more compatibility guides