Type-safe access and
limitless scale with
Prisma & PlanetScale

Query data from PlanetScale with Prisma – a next-generation ORM for Node.js and TypeScript.

What is Prisma?

Prisma makes working with data easy! It offers a type-safe Node.js & TypeScript ORM, global database caching, connection pooling, and real-time database events.

Query
// Creating a new record
await prisma.user.create({
firstName: “Alice”,
email: “alice@prisma.io”
})
Table
id firstName email
1 Bobby bobby@tables.io
2 Nilufar nilu@email.com
3 Jürgen jums@dums.edu
4 Alice alice@prisma.io

How Prisma and PlanetScale fit together

PlanetScale is a MySQL-compatible, serverless database powered by Vitess, which is a database clustering system for horizontal scaling of MySQL. PlanetScale brings many of the benefits of serverless to the database world, with limitless scaling, consumption based pricing, zero-downtime schema migrations, and a generous free tier.

Prisma is an open-source ORM that integrates seamlessly with PlanetScale and supports the full development cycle. Prisma helps you define your database schema declaratively using the Prisma schema fetch data from PlanetScale with full type safety using Prisma Client. Used together, you get all the established benefits of relational databases in addition to a modern developer experience, type safe querying, zero ops, and infinite scale.

Prisma Schema

The Prisma schema uses Prisma's modeling language to define your database schema. It makes data modeling easy and intuitive, especially when it comes to modeling relations.

The syntax of the Prisma schema is heavily inspired by GraphQL SDL. If you're already familiar with SDL, picking it up to model your database tables will be a breeze.

1// Define the `User` table in the database
2model User {
3 id String @id @default(cuid())
4 email String @unique
5 password String
6 name String?
7 posts Post[]
8}
9
10// Define the `Post` table in the database
11model Post {
12 id String @id @default(cuid())
13 title String
14 content String?
15 authorId String
16 author User @relation(fields: [authorId], references: [id])
17}

“PlanetScale & Prisma is an unrivaled combination, bringing a supreme developer experience and proven scalability.”

Sam LambertSam Lambert -
CEO of PlanetScale

Why Prisma and PlanetScale?

Non-blocking schema changes

PlanetScale provide a schema change workflow that allows you to update and evolve your database schema without locking or causing downtime for production databases.

Intuitive data modeling

Prisma's modeling language is declarative and lets you intuitively describe your database schema.

Type-safe database client

Prisma Client ensures fully type-safe database queries with benefits like autocompletion - even in JavaScript.

Built for serverless

Avoid the pitfalls of managing servers and deploy your Prisma & PlanetScale project to serverless runtimes for zero ops and limitless scalability.

Easy database migrations

Map your Prisma schema to the database so you don't need to write SQL to manage your database schema.

Filters, pagination & ordering

Prisma Client reduces boilerplates by providing convenient APIs for common database features.

course

Prisma & PlanetScale best practices

In this video, Daniel guides through everything you need to know when using Prisma with PlanetScale. Learn more about referential integrity and how to operate without foreign key constraints, migration workflows with Prisma and PlanetScale using the prisma db push command, and defining indices on relation scalars (the foreign key fields) for optimal performance.

talk

Database as code with PlanetScale and Prisma

In this talk from Next.js Conf, Taylor Barnett from the PlanetScale team delves into the idea of practicing databases as code, how you can use PlanetScale with Prisma to define your models in a declarative nature and use branching to experiment with your database in an isolated development environment in a serverless stack.

Our Prisma & PlanetScale Resources

Using Prisma with PlanetScale

This document discusses the concepts behind using Prisma and PlanetScale, explains the commonalities and differences between PlanetScale and other database providers, and leads you through the process for configuring your application to integrate with PlanetScale.

Scaling databases for serverless: Chat with Sugu Sougoumarane

Today, Vitess is the default database for scale at Slack, Roblox, Square, Etsy, GitHub, and many more. But how did it get here? From its creation at YouTube to the database that powers PlanetScale, a serverless database platform, Taylor and Sugu will dive into Vitess' creation, why MySQL, what makes Vitess so powerful, and the different ways it is a great fit for developers building serverless applications.