# Prisma ORM (/docs/orm)

Location: Prisma ORM

Prisma ORM is [open-source](https://github.com/prisma/prisma) and consists of:

* [**Prisma Client**](/orm/prisma-client): Auto-generated, type-safe **ORM interface**
* [**Prisma Migrate**](/orm/prisma-migrate): Database migration system
* [**Prisma Studio**](https://www.prisma.io/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.

Why Prisma ORM [#why-prisma-orm]

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](https://en.wikipedia.org/wiki/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

When to use Prisma [#when-to-use-prisma]

**Prisma is a good fit if you:**

* Build server-side applications (REST, GraphQL, gRPC, serverless)
* Value type safety and developer experience
* 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)

How it works [#how-it-works]

1. Define your schema [#1-define-your-schema]

The [Prisma schema](/orm/prisma-schema/overview) defines your data models and database connection:

```prisma
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?
}
```

2. Configure your connection [#2-configure-your-connection]

Create a `prisma.config.ts` file in your project root:

```ts title="prisma.config.ts"
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"),
  },
});
```

3. Run migrations [#3-run-migrations]

Use [Prisma Migrate](/orm/prisma-migrate) to create and apply migrations:

  

#### npm

```bash
npx prisma migrate dev
```

#### pnpm

```bash
pnpm dlx prisma migrate dev
```

#### yarn

```bash
yarn dlx prisma migrate dev
```

#### bun

```bash
bunx --bun prisma migrate dev
```

Or [introspect](/orm/prisma-schema/introspection) an existing database:

  

#### npm

```bash
npx prisma db pull
```

#### pnpm

```bash
pnpm dlx prisma db pull
```

#### yarn

```bash
yarn dlx prisma db pull
```

#### bun

```bash
bunx --bun prisma db pull
```

4. Query with Prisma Client [#4-query-with-prisma-client]

Generate and use the type-safe client:

  

#### npm

```bash
npm install @prisma/client
npx prisma generate
```

#### pnpm

```bash
pnpm add @prisma/client
pnpm dlx prisma generate
```

#### yarn

```bash
yarn add @prisma/client
yarn dlx prisma generate
```

#### bun

```bash
bun add @prisma/client
bun x prisma generate
```

```ts
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" },
    },
  },
});
```

> [!NOTE]
> Prisma 7 Connection Requirements [#prisma-7-connection-requirements]
> 
> Starting with **Prisma 7**, providing a [driver adapter](/orm/core-concepts/supported-databases/database-drivers) is mandatory for direct database connections. This change standardizes database connectivity across Node.js, Serverless, and Edge environments.
> 
> If you use Prisma Accelerate, instantiate Prisma Client with `accelerateUrl` and the Accelerate extension instead of a driver adapter.
> 
> To ensure compatibility:
> 
> * **Install an adapter:** Use the specific package for your database (e.g., `@prisma/adapter-pg`, `@prisma/adapter-mysql`, etc.).
> * **Enable ESM:** Your `package.json` must include `"type": "module"`.
> 
> For detailed instructions, see the [V7 Upgrade Guide](/guides/upgrade-prisma-orm/v7).

Next steps [#next-steps]

* [**Prisma schema**](/orm/prisma-schema/overview) - Learn the schema language
* [**Prisma Client**](/orm/prisma-client) - Explore the query API

## Related pages

- [`Build faster with Prisma + AI`](https://www.prisma.io/docs/ai): Build faster with Prisma and AI coding tools like Cursor and ChatGPT
- [`Choose a setup path`](https://www.prisma.io/docs/getting-started): Choose the fastest path to start using Prisma ORM or Prisma Postgres in a new or existing project.
- [`CLI Overview`](https://www.prisma.io/docs/cli): The Prisma CLI is the command-line interface for Prisma ORM. Use it to initialize projects, generate Prisma Client, manage databases, run migrations, and more
- [`Console`](https://www.prisma.io/docs/console): Learn how to use the Console to manage and integrate Prisma products into your application.
- [`Guides`](https://www.prisma.io/docs/guides): A collection of guides for various tasks and workflows