Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import NextSteps from '../../_components/_next-steps.mdx'
Install the packages needed for this quickstart:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv
```

Expand All @@ -34,6 +34,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database
- **`@types/pg`** - TypeScript type definitions for node-postgres
- **`dotenv`** - Loads environment variables from your `.env` file

## 3. Configure ESM support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ In this guide, you will learn how to set up a new TypeScript project from scratc
Install the packages needed for this quickstart:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/better-sqlite3 --save-dev
npm install @prisma/client @prisma/adapter-better-sqlite3 dotenv
```

Expand All @@ -36,6 +36,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-better-sqlite3`** - The SQLite driver adapter that connects Prisma Client to your database
- **`@types/better-sqlite3`** - TypeScript type definitions for better-sqlite3
- **`dotenv`** - Loads environment variables from your `.env` file

## 3. Configure ESM support
Expand Down Expand Up @@ -93,16 +94,13 @@ import { defineConfig, env } from 'prisma/config'

export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
},
datasource: {
url: env('DATABASE_URL'),
},
})
```

Add `dotenv` to `prisma.config.ts` so that Prisma can load environment variables from your `.env` file:
Add `dotenv` and migrations configuration to `prisma.config.ts`:

```typescript file=prisma.config.ts
// add-start
Expand All @@ -112,9 +110,11 @@ import { defineConfig, env } from 'prisma/config'

export default defineConfig({
schema: 'prisma/schema.prisma',
// add-start
migrations: {
path: 'prisma/migrations',
},
// add-end
datasource: {
url: env('DATABASE_URL'),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you don't already have a PostgreSQL database, follow the quickstart to set up
Install the packages needed for this quickstart:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv
```

Expand All @@ -45,6 +45,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database
- **`@types/pg`** - TypeScript type definitions for node-postgres
- **`dotenv`** - Loads environment variables from your `.env` file

## 3. Configure ESM support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ You also need:
Install the packages needed for this quickstart:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/mssql --save-dev
npm install @prisma/client @prisma/adapter-mssql dotenv
```

Expand All @@ -41,6 +41,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-mssql`** - The SQL Server driver adapter that connects Prisma Client to your database
- **`@types/mssql`** - TypeScript type definitions for mssql
- **`dotenv`** - Loads environment variables from your `.env` file

## 3. Configure ESM support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ You also need:
Install the packages needed for this quickstart:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv
```

Expand All @@ -39,6 +39,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma migrate`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database (CockroachDB is PostgreSQL-compatible)
- **`@types/pg`** - TypeScript type definitions for node-postgres
- **`dotenv`** - Loads environment variables from your `.env` file

## 3. Configure ESM support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NextSteps from '../../_components/_next-steps.mdx'
Navigate to your existing project directory and install the required dependencies:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv
```

Expand All @@ -29,6 +29,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database
- **`@types/pg`** - TypeScript type definitions for node-postgres
- **`dotenv`** - Loads environment variables from your `.env` file

## 2. Initialize Prisma ORM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NextSteps from '../../_components/_next-steps.mdx'
Navigate to your existing project directory and install the required dependencies:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/better-sqlite3 --save-dev
npm install @prisma/client @prisma/adapter-better-sqlite3 dotenv
```

Expand All @@ -29,6 +29,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-better-sqlite3`** - The SQLite driver adapter that connects Prisma Client to your database
- **`@types/better-sqlite3`** - TypeScript type definitions for better-sqlite3
- **`dotenv`** - Loads environment variables from your `.env` file

## 2. Initialize Prisma ORM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NextSteps from '../../_components/_next-steps.mdx'
Navigate to your existing project directory and install the required dependencies:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv
```

Expand All @@ -29,6 +29,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database
- **`@types/pg`** - TypeScript type definitions for node-postgres
- **`dotenv`** - Loads environment variables from your `.env` file

## 2. Initialize Prisma ORM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NextSteps from '../../_components/_next-steps.mdx'
Navigate to your existing project directory and install the required dependencies:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/mssql --save-dev
npm install @prisma/client @prisma/adapter-mssql dotenv
```

Expand All @@ -30,6 +30,7 @@ Here's what each package does:
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-mssql`** - The SQL Server driver adapter that connects Prisma Client to your database
- **`dotenv`** - Loads environment variables from your `.env` file
- **`@types/mssql`** - TypeScript type definitions for mssql

## 2. Initialize Prisma ORM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import NextSteps from '../../_components/_next-steps.mdx'
Navigate to your existing project directory and install the required dependencies:

```terminal
npm install prisma @types/node --save-dev
npm install prisma @types/node @types/pg --save-dev
npm install @prisma/client @prisma/adapter-pg dotenv
```

Expand All @@ -29,6 +29,7 @@ Here's what each package does:
- **`prisma`** - The Prisma CLI for running commands like `prisma init`, `prisma db pull`, and `prisma generate`
- **`@prisma/client`** - The Prisma Client library for querying your database
- **`@prisma/adapter-pg`** - The [`node-postgres` driver adapter](/orm/overview/databases/postgresql#using-the-node-postgres-driver) that connects Prisma Client to your database (CockroachDB is PostgreSQL-compatible)
- **`@types/pg`** - TypeScript type definitions for node-postgres
- **`dotenv`** - Loads environment variables from your `.env` file

## 2. Initialize Prisma ORM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,57 @@ npx prisma@latest init --db
<cmdResult>

```code no-copy wrap
Success! Your Prisma Postgres database is ready ✅
✓ Select an authentication method Google
Authenticating to Prisma Platform via browser.

We created an initial schema.prisma file and a .env file with your DATABASE_URL environment variable already set.
Visit the following URL in your browser to authenticate:
https://console.prisma.io/auth/cli?state=eyJjb6ll...

Successfully authenticated as jon@doe.com.
Let's set up your Prisma Postgres database!
✓ Select your region: ap-southeast-1 - Asia Pacific (Singapore)
✓ Enter a project name: My Prisma Project
✓ Success! Your Prisma Postgres database is ready ✅

We found an existing schema.prisma file in your current project directory.

--- Database URL ---

Connect Prisma ORM to your Prisma Postgres database with this URL:

--- Next steps ---

Go to https://pris.ly/ppg-init for detailed instructions.

1. Define your database schema
Open the schema.prisma file and define your first models. Check the docs if you need inspiration: https://pris.ly/ppg-init
1. Install the Postgres adapter
npm install @prisma/adapter-pg

...and add it to your Prisma Client instance:

import { PrismaClient } from "./generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";

const connectionString = `${process.env.DATABASE_URL}`;

const adapter = new PrismaPg({ connectionString });
const prisma = new PrismaClient({ adapter });

2. Apply migrations
Run the following command to create and apply a migration:
npx prisma migrate dev --name init
npx prisma migrate dev

3. Manage your data
View and edit your data locally by running this command:
View and edit your data locally by running this command:
npx prisma studio

... or online in Console:
https://console.prisma.io/cliwxim5p005xqh0g3mvqpyak/cm6kw97t801ijzhvfwz4a0my3/cm6kw97ta01ikzhvf965vresv/studio
...or online in Console:
https://console.prisma.io/$path

4. Send queries from your app
To access your database from a JavaScript/TypeScript app, you need to use Prisma ORM. Go here for step-by-step instructions: https://pris.ly/ppg-init
If you already have an existing app with Prisma ORM, you can now run it and it will send queries against your newly created Prisma Postgres instance.

5. Learn more
For more info, visit the Prisma Postgres docs: https://pris.ly/ppg-docs
```

</cmdResult>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ datasource db {
// add-start
provider = "postgres"
// add-end
url = env("DATABASE_URL")
}
```

Expand Down
43 changes: 21 additions & 22 deletions content/200-orm/050-overview/500-databases/200-database-drivers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ One of Prisma Client's components is the [Query Engine](/orm/more/under-the-hood

:::note

As of [v6.15.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without Rust engines in production applications. Learn more [here](/orm/prisma-client/setup-and-configuration/no-rust-engine).
As of Prisma ORM 7, the query compiler (client engine) is the default, which means Prisma Client is generated without a Rust-based query engine binary. This provides better performance and developer experience. Learn more [here](/orm/prisma-client/setup-and-configuration/no-rust-engine).

**When enabled, your Prisma Client will be generated without a Rust-based query engine binary**:
In Prisma ORM 7, the default generator configuration is:

```prisma
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
engineType = "client" // no Rust engine
provider = "prisma-client"
output = "../generated/prisma"
}
```

Note that [driver adapters](/orm/overview/databases/database-drivers#driver-adapters) are required if you want to use Prisma ORM without Rust engines.
Note that [driver adapters](/orm/overview/databases/database-drivers#driver-adapters) are required when using the query compiler.

You can [read about the performance and DX improvements](https://www.prisma.io/blog/prisma-orm-without-rust-latest-performance-benchmarks) of this change on our blog.

Expand Down Expand Up @@ -120,7 +119,7 @@ As of the 6.6.0 release, you instantiate the driver adapter _directly_ with the

```typescript
import { PrismaLibSQL } from '@prisma/adapter-libsql'
import { PrismaClient } from '../prisma/prisma-client'
import { PrismaClient } from '../generated/prisma/client'

const adapter = new PrismaLibSQL({
url: env.LIBSQL_DATABASE_URL,
Expand All @@ -130,27 +129,28 @@ const adapter = new PrismaLibSQL({
const prisma = new PrismaClient({ adapter })
```

### Driver adapters don't read the connection string from the Prisma schema
### Driver adapters and database connection configuration

When using Prisma ORM's built-in drivers, the connection string is read from the `url` field of the `datasource` block in your Prisma schema.
In Prisma ORM 7, the database connection URL is configured in [`prisma.config.ts`](/orm/reference/prisma-config-reference). However, when using a driver adapter, the connection string needs to be provided in your _application code_ when the driver adapter is set up initially.

On the other hand, when using a driver adapter, the connection string needs to be provided in your _application code_ when the driver adapter is set up initially. Here is how this is done for the `pg` driver and the `@prisma/adapter-pg` adapter:
Here is how this is done for the `pg` driver and the `@prisma/adapter-pg` adapter:

```ts
import { PrismaClient } from '../prisma/generated/client'
import 'dotenv/config'
import { PrismaClient } from '../generated/prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'

const adapter = new PrismaPg({ connectionString: env.DATABASE_URL })
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL })
const prisma = new PrismaClient({ adapter })
```

See the docs for the driver adapter you're using for concrete setup instructions.

### Driver adapters and custom output paths

Since Prisma 5.9.0, when using the driver adapters Preview feature along with a [custom output path for Prisma Client](/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path), you cannot reference Prisma Client using a relative path.
In Prisma ORM 7, the recommended approach is to use a custom output path for Prisma Client. The default output path is `../generated/prisma`.

Let's assume you had `output` in your Prisma schema set to `../src/generated/client`:
Let's assume you have `output` in your Prisma schema set to `../generated/prisma`:

```prisma
generator client {
Expand All @@ -159,39 +159,38 @@ generator client {
}
```

What you should _not_ do is reference that path relatively:
You can reference Prisma Client using a relative path from your application code:

```ts no-copy
// what not to do!
import { PrismaClient } from './src/generated/client'
```ts
import { PrismaClient } from '../generated/prisma/client'

const client = new PrismaClient()
```

Instead, you will need to use a linked dependency.
Alternatively, you can use a linked dependency for cleaner imports.

<TabbedContent code>

<TabItem value="npm">

```terminal
npm add db@./src/generated/client
npm add db@./generated/prisma
```

</TabItem>

<TabItem value="pnpm">

```terminal
pnpm add db@link:./src/generated/client
pnpm add db@link:./generated/prisma
```

</TabItem>

<TabItem value="yarn">

```terminal
yarn add db@link:./src/generated/client
yarn add db@link:./generated/prisma
```

</TabItem>
Expand Down
Loading
Loading