Skip to main content

Set up

To get started:
1
Install the Prisma driver adapter for PlanetScale (@prisma/adapter-planetscale) and PlanetScale serverless driver (@planetscale/database) packages:
npm install @prisma/adapter-planetscale @planetscale/database
2
Update your prisma/schema.prisma file:
// schema.prisma
generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider     = "mysql"
  url          = env("DATABASE_URL")
  relationMode = "prisma"
}
Ensure you update the host value in your connection string to aws.connect.psdb.cloud. You can learn more about this here.
3
Generate Prisma Client:
npx prisma generate
4
Update your Prisma Client instance to use the PlanetScale serverless driver:
import "dotenv/config"
import { PrismaPlanetScale } from '@prisma/adapter-planetscale'
import { PrismaClient } from './generated/prisma/client.js'

const adapter = new PrismaPlanetScale({ url: process.env.DATABASE_URL })
const prisma = new PrismaClient({ adapter })

async function main() {
  const posts = await prisma.post.findMany()
  console.log(posts)
}
You can then use Prisma Client as you usually would with auto-completion and full type-safety.

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.