Prisma 7
Prisma ORM is a next-generation Node.js and TypeScript ORM that provides type-safe database access, migrations, and a visual data editor. Applies to Prisma ORM v7.
Prisma ORM is open-source and consists of:
- Prisma Client: Auto-generated, type-safe ORM interface
- Prisma Migrate: Database migration system
- Prisma Studio: GUI to view and edit your data
Prisma Client works with any Node.js or TypeScript backend, whether you're deploying to traditional servers, serverless functions, or microservices.
Quickstart
Prisma ORM 7 with Prisma Postgres in about 5 minutes.
Add to an existing project
Introspect your database and start querying with Prisma ORM 7.
Prisma 8 docs
The docs for the current major version.
If you're working with a coding agent, copy the prompt below, or start from the getting started page for the full stack.
Add Prisma ORM 7 to this project with my existing database.
If I have not given you a database connection string and none exists in the project, stop and ask.
1. Run `npx prisma@prev init` (Prisma 7). For an existing database, set DATABASE_URL in `.env` and introspect it with `npx prisma@prev db pull`; for a new schema, define models in `prisma/schema.prisma` and run `npx prisma@prev migrate dev --name init`. If migrate dev asks to reset the database, stop and ask me first.
2. Install the driver adapter for the database (Prisma 7 requires one), e.g. `npm install @prisma/adapter-pg` for PostgreSQL, and pass it to `new PrismaClient({ adapter })`. Generate the client with `npx prisma@prev generate` and write one query in an existing code path.
3. Run the query (e.g. with `npx tsx`) and show me the output, the schema, and the query you added.
Current docs: https://www.prisma.io/docs/orm/v7.md and https://www.prisma.io/docs/llms.txt.Traditional database tools force a tradeoff between productivity and control. Raw SQL gives full control but is error-prone and lacks type safety. Traditional ORMs improve productivity but abstract too much, leading to the object-relational impedance mismatch and performance pitfalls like the n+1 problem.
Prisma takes a different approach:
- Type-safe queries validated at compile time with full autocompletion
- Thinking in objects without the complexity of mapping relational data
- Plain JavaScript objects returned from queries, not complex model instances
- Single source of truth in the Prisma schema for database and application models
- Healthy constraints that prevent common pitfalls and anti-patterns
Prisma is a good fit if you:
- Build server-side applications (REST, GraphQL, gRPC, serverless)
- Want type safety and editor autocompletion for queries
- Work in a team and want a clear, declarative schema
- Need migrations, querying, and data modeling in one toolkit
Consider alternatives if you:
- Need full control over every SQL query (use raw SQL drivers)
- Want a no-code backend (use a BaaS like Supabase or Firebase)
- Need an auto-generated CRUD GraphQL API (use Hasura or PostGraphile)
The Prisma schema defines your data models and database connection:
datasource db {
provider = "postgresql"
}
generator client {
provider = "prisma-client"
output = "./generated"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
published Boolean @default(false)
author User? @relation(fields: [authorId], references: [id])
authorId Int?
}Create a prisma.config.ts file in your project root:
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: env("DATABASE_URL"),
},
});Use Prisma Migrate to create and apply migrations:
bunx prisma@prev migrate devpnpm dlx prisma@prev migrate devyarn dlx prisma@prev migrate devnpx prisma@prev migrate devOr introspect an existing database:
bunx prisma@prev db pullpnpm dlx prisma@prev db pullyarn dlx prisma@prev db pullnpx prisma@prev db pullGenerate and use the type-safe client:
bun add @prisma/client@7
bunx prisma@prev generatepnpm add @prisma/client@7
pnpm dlx prisma@prev generateyarn add @prisma/client@7
yarn dlx prisma@prev generatenpm install @prisma/client@7
npx prisma@prev generateimport { PrismaClient } from "./generated/client";
// Import the driver adapter for your specific database (example uses PostgreSQL)
import { PrismaPg } from "@prisma/adapter-pg";
// Initialize the adapter according to your driver's requirements
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
// Pass the adapter instance to PrismaClient
const prisma = new PrismaClient({ adapter });
// Find all users with their posts
const users = await prisma.user.findMany({
include: { posts: true },
});
// Create a user with a post
const user = await prisma.user.create({
data: {
email: "alice@prisma.io",
posts: {
create: { title: "Hello World" },
},
},
});import { PrismaClient } from "./generated/client";
// Import the driver adapter for your specific database (example uses PostgreSQL)
import { PrismaPg } from "@prisma/adapter-pg";
// Initialize the adapter according to your driver's requirements
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
// Pass the adapter instance to PrismaClient
const prisma = new PrismaClient({ adapter });
// Find all users with their posts
const users = await prisma.user.findMany({
include: { posts: true },
});
// Create a user with a post
const user = await prisma.user.create({
data: {
email: "alice@prisma.io",
posts: {
create: { title: "Hello World" },
},
},
});- Prisma schema - Learn the schema language
- Prisma Client - Explore the query API