Skip to content
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e35e705
DC-5044 `prisma-client-js` deprecated (#7219)
aidankmcalister Nov 4, 2025
ef969c8
feat: restructure getting started side nav
ankur-arch Nov 4, 2025
f8c32d1
DC-5040 Env Vars via Config (#7227)
aidankmcalister Nov 5, 2025
87eba65
urls deprecated (#7226)
aidankmcalister Nov 5, 2025
ac89f6a
minimum version uodated (#7234)
aidankmcalister Nov 7, 2025
3bf085d
DC-5043 Middleware removed from docs (#7233)
aidankmcalister Nov 7, 2025
4c19f41
feat: add prisma-orm quickstarts
ankur-arch Nov 10, 2025
8e5616e
fix: update times and add proper links
ankur-arch Nov 10, 2025
2a19cb7
fix: instropspect changes
ankur-arch Nov 10, 2025
5ac553e
feat: add get started from prisma orm page
ankur-arch Nov 10, 2025
ac2695e
feat: add other orms
ankur-arch Nov 11, 2025
6352851
fix: update other tools + ppg
ankur-arch Nov 11, 2025
eda1224
fix: add more clarity
ankur-arch Nov 11, 2025
2ca1ef2
fix: add prisma postgres
ankur-arch Nov 11, 2025
671e4cd
feat: clear migrate from early access
ankur-arch Nov 11, 2025
ab6ee45
fix: add to existing dbs sections
ankur-arch Nov 11, 2025
04dd079
Merge branch 'prisma-7' into prisma-7-getting-started-restructure
ankur-arch Nov 11, 2025
f3365e8
fix: clean-up docs files
ankur-arch Nov 11, 2025
fc7d28a
fix: typeorm missing urls
ankur-arch Nov 11, 2025
4276072
fix: broken link
ankur-arch Nov 11, 2025
4a0e0c6
fix: update titles
ankur-arch Nov 11, 2025
dc82e47
fix: add generate step + sqlite fixes
ankur-arch Nov 12, 2025
7edbd6f
Merge branch 'main' into prisma-7-getting-started-restructure
ankur-arch Nov 13, 2025
ddf0c20
fix: clean-up redirects file DC-6228
ankur-arch Nov 13, 2025
aa486e9
fix: clean-up unnecessary file
ankur-arch Nov 13, 2025
59db9d6
fix: remove unknown word
ankur-arch Nov 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
# yaml template to refer to https://docs.coderabbit.ai/reference/yaml-template#enterprise
language: "en-US"
tone_instructions: "You are a principal engineer with natural teaching abilities. You detect issues and clearly explain why."
reviews:
collapse_walkthrough: false
profile: "chill"
Expand All @@ -14,6 +15,7 @@ reviews:
auto_review:
enabled: true
drafts: false
base_branches: [".*"]
finishing_touches:
docstrings:
enabled: false
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/lychee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
--cache
--cache-exclude-status 429,500,502,503,504
--max-cache-age 5m
--verbose
--no-progress
--accept 200,201,204,304,403,429
--timeout 20
Expand All @@ -50,7 +49,6 @@ jobs:
args: >
--cache
--max-cache-age 5m
--verbose
--no-progress
--accept 200,201,204,304,403,429
--cache-exclude-status 429,500,502,503,504
Expand Down Expand Up @@ -79,8 +77,8 @@ jobs:
fi

if [ -n "$REPORT_FILE" ]; then
# Read the original output
ORIGINAL=$(cat "$REPORT_FILE")
# Read the original output and remove everything after 'Redirects per input'
ORIGINAL=$(cat "$REPORT_FILE" | sed '/^##* Redirects per input/,$d')

# Create formatted output
cat > lychee/formatted.md << EOF
Expand All @@ -92,7 +90,7 @@ jobs:

EOF

# Append the original content with title replacement
# Append the cleaned content with title replacement
echo "$ORIGINAL" | sed 's/^# Summary$//' | sed 's/^## Summary$//' >> lychee/formatted.md
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ In this Quickstart guide, you'll learn how to get started from scratch with Pris

:::note

If you want to use Prisma Postgres with another ORM or database library (like Drizzle ORM, TypeORM or Kysely), you can follow the instructions [here](/postgres/introduction/getting-started#connect-via-any-database-library--tool).
If you want to use Prisma Postgres with another ORM or database library (like Drizzle ORM, TypeORM or Kysely), you can follow the instructions [here](/postgres/getting-started#connect-via-any-database-library--tool).

:::

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
---
title: 'Prisma Postgres'
metaTitle: 'Quickstart: Prisma ORM with Prisma Postgres (5 min)'
metaDescription: 'Create a new TypeScript project from scratch by connecting Prisma ORM to Prisma Postgres and generating a Prisma Client for database access.'
sidebar_custom_props: { badge: '5 min' }
---

import Prerequisites from '../../_components/_prerequisites.mdx'
import CreateProject from '../../_components/_create-project.mdx'
import ExploreData from '../../_components/_explore-data.mdx'
import NextSteps from '../../_components/_next-steps.mdx'

[Prisma Postgres](/postgres) is a fully managed PostgreSQL database that scales to zero and integrates smoothly with both Prisma ORM and Prisma Studio. In this guide, you will learn how to set up a new TypeScript project from scratch, connect it to Prisma Postgres using Prisma ORM, and generate a Prisma Client for easy, type-safe access to your database.

## Prerequisites

<Prerequisites />

## 1. Create a new project

<CreateProject />

## 2. Install required dependencies

Install the packages needed for this quickstart:

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

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
- **`dotenv`** - Loads environment variables from your `.env` file

## 3. Configure ESM Support

Update `tsconfig.json` for ESM compatibility:

```json file=tsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"target": "ES2023",
"strict": true,
"esModuleInterop": true,
"ignoreDeprecations": "6.0"
}
}
```

Update `package.json` to enable ESM:

```json file=package.json
{
// add-start
"type": "module",
// add-end
}
```

## 4. Initialize Prisma ORM and create a Prisma Postgres database

You can now invoke the Prisma CLI by prefixing it with `npx`:

```terminal
npx prisma
```

Next, set up your Prisma ORM project by creating your [Prisma Schema](/orm/prisma-schema) file with the following command:

```terminal
npx prisma init --db --output ../generated/prisma
```

:::info

You'll need to answer a few questions while setting up your Prisma Postgres database. Select the region closest to your location and a memorable name for your database.

:::

This command does a few things:

- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
- Creates a new Prisma Postgres database (when using `--db` flag)
- Creates a `.env` file in the root directory for environment variables
- Generates the Prisma Client in the `generated/prisma/` directory
- Creates a `prisma.config.ts` file for Prisma configuration

The generated `prisma.config.ts` file looks like this:

```typescript file=prisma.config.ts
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:

```typescript file=prisma.config.ts
// add-start
import 'dotenv/config'
// add-end
import { defineConfig, env } from 'prisma/config'

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

The generated schema uses [the ESM-first `prisma-client` generator](/orm/prisma-schema/overview/generators#prisma-client) with a custom output path:

```prisma file=prisma/schema.prisma
generator client {
provider = "prisma-client"
output = "../generated/prisma"
}

datasource db {
provider = "postgresql"
}
```

## 5. Define your data model

Open `prisma/schema.prisma` and add the following models:

```prisma file=prisma/schema.prisma
generator client {
provider = "prisma-client"
output = "../generated/prisma"
}

datasource db {
provider = "postgresql"
}

//add-start
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}

model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}
//add-end
```

## 6. Create and apply your first migration

Create your first migration to set up the database tables:

```terminal
npx prisma migrate dev --name init
```

This command:
- Creates the database tables based on your schema
- Generates the Prisma Client in the `generated/prisma` directory

## 7. Instantiate Prisma Client

Now that you have all the dependencies installed, you can instantiate Prisma Client. You need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor:

```typescript file=lib/prisma.ts
import "dotenv/config";
import { PrismaPg } from '@prisma/adapter-pg'
import { PrismaClient } from '../generated/prisma/client'

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

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

export { prisma }
```

## 8. Write your first query

Create a `script.ts` file to test your setup:

```typescript file=script.ts
import { prisma } from './lib/prisma'

async function main() {
// Create a new user with a post
const user = await prisma.user.create({
data: {
name: 'Alice',
email: '[email protected]',
posts: {
create: {
title: 'Hello World',
content: 'This is my first post!',
published: true,
},
},
},
include: {
posts: true,
},
})
console.log('Created user:', user)

// Fetch all users with their posts
const allUsers = await prisma.user.findMany({
include: {
posts: true,
},
})
console.log('All users:', JSON.stringify(allUsers, null, 2))
}

main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})
```

Run the script:

```terminal
npx tsx script.ts
```

You should see the created user and all users printed to the console!

## 9. Explore your data with Prisma Studio

<ExploreData />

## Next steps

<NextSteps />

## More info

- [Prisma Postgres documentation](/postgres)
- [Prisma Config reference](/orm/reference/prisma-config-reference)
- [Database connection management](/orm/prisma-client/setup-and-configuration/databases-connections)
Loading
Loading