Skip to content

Commit 7c8ab87

Browse files
ankur-archclaude
andcommitted
docs(guides): add Prisma Next guides with a Guides version dropdown (DR-8689)
- Add a "Guides version" dropdown to the guides section, mirroring the CLI pattern: /guides stays the Prisma 7 tree, /guides/next holds the Prisma Next tree. version.ts, the version switcher, and the versioned sidebar tree gain guides handling; the latest sidebar hides the next tree and vice versa (verified via rendered anchors). - First converted batch, every flow run end to end against live Prisma Postgres databases before writing: Bun (scaffold, emit, db init, first typed query with real output), Deno (same flow plus the .ts import-extension and permission-flag differences, both hit and documented), and Hono (template scaffold, seed, GET /users served over HTTP, plus an added POST route returning the created row). Outputs in the guides are captured from the runs. - Each guide documents the template's flat-model-path issue honestly (db.orm.User -> db.orm.public.User) until the templates are fixed. - Document the future guides URL cutover ("/" becomes /v7) as a commented, reviewable block in next.config.mjs: promote /guides/next/* to /guides/*, park converted Prisma 7 guides under /guides/v7/*, per-guide pairs appended as each conversion lands. - /guides/next index explains what is converted, what lands next per DR-8689, and where to go meanwhile. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent f74f219 commit 7c8ab87

10 files changed

Lines changed: 583 additions & 3 deletions

File tree

apps/docs/content/docs/guides/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"icon": "NotebookTabs",
55
"pages": [
66
"index",
7+
"next",
78
"frameworks",
89
"runtimes",
910
"deployment",
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: How to use Prisma Next with Bun
3+
description: Scaffold a Prisma Next app with Bun, initialize your database, and run your first typed query.
4+
url: /guides/next/bun
5+
metaTitle: How to use Prisma Next with Bun
6+
metaDescription: Set up a Prisma Next project with Bun and Prisma Postgres, from scaffold to first query, with tested commands and real output.
7+
badge: early-access
8+
---
9+
10+
## Introduction
11+
12+
In this guide, you scaffold a Prisma Next project with Bun, initialize a PostgreSQL database from your schema, and run your first typed query. Bun runs TypeScript directly, so there is no build step anywhere in the flow.
13+
14+
Every command and code sample below was run end to end against a live Prisma Postgres database.
15+
16+
## Prerequisites
17+
18+
- [Bun](https://bun.sh/) 1.1 or later (`bun --version`)
19+
- A PostgreSQL connection string, or nothing at all: the scaffold can create a [Prisma Postgres](/postgres) database for you
20+
21+
## 1. Scaffold the project
22+
23+
Create the project with `create-prisma`. Pick Bun as the package manager when prompted, or pass everything up front:
24+
25+
```bash
26+
bunx create-prisma@next create my-bun-app --provider postgres --package-manager bun
27+
```
28+
29+
When the prompt asks about the database, pick Prisma Postgres to have one created for you, or paste your own `DATABASE_URL`. The scaffold writes the connection string to `.env`, sets up `src/prisma/` with a starter schema, and installs dependencies with Bun.
30+
31+
```bash
32+
cd my-bun-app
33+
```
34+
35+
## 2. Emit the contract and initialize the database
36+
37+
Prisma Next compiles your schema (`src/prisma/contract.prisma`) into a contract that your queries are type-checked against. Emit it, then apply the schema to the database:
38+
39+
```bash
40+
bun run contract:emit
41+
bun run db:init
42+
```
43+
44+
`db:init` creates the tables and signs the database:
45+
46+
```text no-copy
47+
"summary": "Applied 5 operation(s) across 1 space(s), database signed"
48+
```
49+
50+
If `db:init` reports that the contract file is missing, run `bun run contract:emit` first; the emit step generates `src/prisma/contract.json`.
51+
52+
## 3. Write your first query
53+
54+
Replace `src/index.ts` with a script that creates a user and reads every user back. Model access is namespace-qualified on PostgreSQL: `db.orm.public.User`, where `public` is the default schema.
55+
56+
```ts title="src/index.ts"
57+
import { db } from "./prisma/db";
58+
59+
// Create a user, then read every user back
60+
const user = await db.orm.public.User.create({
61+
email: `ada+${Date.now()}@prisma.io`,
62+
name: "Ada Lovelace",
63+
});
64+
console.log(`created user ${user.email}`);
65+
66+
const users = await db.orm.public.User.select("id", "email", "name").all();
67+
console.log(`there are now ${users.length} users`);
68+
69+
await db.close();
70+
```
71+
72+
`await db.close()` at the end lets the script exit cleanly; without it, the connection pool keeps the process alive.
73+
74+
## 4. Run it
75+
76+
```bash
77+
bun run dev
78+
```
79+
80+
```text no-copy
81+
created user ada+1783380852695@prisma.io
82+
there are now 2 users
83+
```
84+
85+
That is the whole loop: schema to contract, contract to database, typed queries against both.
86+
87+
## Common gotchas
88+
89+
:::warning
90+
91+
The starter `seed.ts` and `users.ts` files in some templates still address models with the older flat form (`db.orm.User`), which fails at runtime with `Cannot read properties of undefined`. If you use them, change the model access to `db.orm.public.User`.
92+
93+
:::
94+
95+
## Prompt your coding agent
96+
97+
The scaffold installs Prisma Next skills for your coding agent. Prompts that map to this guide:
98+
99+
- "Using the prisma-next-queries skill, add a script that lists the 10 newest users."
100+
- "Add a Post model related to User, emit the contract, and update the database."
101+
102+
## Next steps
103+
104+
- [Read the Prisma Next overview](/orm/next) for the concepts behind contracts and typed queries.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: How to use Prisma Next with Deno
3+
description: Run Prisma Next on Deno, including the import-extension and permission differences that matter.
4+
url: /guides/next/deno
5+
metaTitle: How to use Prisma Next with Deno
6+
metaDescription: Set up a Prisma Next project on Deno with Prisma Postgres, from scaffold to first query, with tested commands and real output.
7+
badge: early-access
8+
---
9+
10+
## Introduction
11+
12+
In this guide, you scaffold a Prisma Next project for Deno, initialize a PostgreSQL database, and run your first typed query. Deno runs TypeScript natively and installs npm packages on demand, so the flow is close to the [Bun guide](/guides/next/bun) with two Deno-specific differences this guide calls out: explicit import extensions and permission flags.
13+
14+
Every command and code sample below was run end to end against a live Prisma Postgres database.
15+
16+
## Prerequisites
17+
18+
- [Deno](https://deno.com/) 2.0 or later (`deno --version`)
19+
- A PostgreSQL connection string, or nothing at all: the scaffold can create a [Prisma Postgres](/postgres) database for you
20+
21+
## 1. Scaffold the project
22+
23+
`create-prisma` supports Deno as a package manager choice:
24+
25+
```bash
26+
deno run -A npm:create-prisma@next create my-deno-app --provider postgres --package-manager deno
27+
```
28+
29+
Pick Prisma Postgres at the database prompt to have a database created for you, or paste your own `DATABASE_URL`. The generated `package.json` scripts wrap every command in `deno run -A --env-file=.env`, so environment variables load without a dotenv import.
30+
31+
```bash
32+
cd my-deno-app
33+
deno install
34+
```
35+
36+
## 2. Emit the contract and initialize the database
37+
38+
```bash
39+
deno run -A --env-file=.env npm:prisma-next contract emit
40+
deno run -A --env-file=.env npm:prisma-next db init
41+
```
42+
43+
The first command compiles `src/prisma/contract.prisma` into the contract your queries are type-checked against. The second creates the tables and signs the database.
44+
45+
The `-A` flag grants the permissions the CLI needs (network for the database, filesystem for the generated files). To scope permissions tighter, start from `--allow-net --allow-read --allow-write --allow-env` and adjust to your setup.
46+
47+
## 3. Write your first query
48+
49+
Replace `src/index.ts`. Two things to notice: Deno requires the `.ts` extension on relative imports, and model access is namespace-qualified on PostgreSQL (`db.orm.public.User`):
50+
51+
```ts title="src/index.ts"
52+
import { db } from "./prisma/db.ts";
53+
54+
// Create a user, then read every user back
55+
const user = await db.orm.public.User.create({
56+
email: `grace+${Date.now()}@prisma.io`,
57+
name: "Grace Hopper",
58+
});
59+
console.log(`created user ${user.email}`);
60+
61+
const users = await db.orm.public.User.select("id", "email", "name").all();
62+
console.log(`there are now ${users.length} users`);
63+
64+
await db.close();
65+
```
66+
67+
If you see `Module not found "file:///…/src/prisma/db"`, the import is missing its `.ts` extension. Deno does not resolve relative imports without an extension.
68+
69+
## 4. Run it
70+
71+
```bash
72+
deno task dev
73+
```
74+
75+
```text no-copy
76+
created user grace+1783380988819@prisma.io
77+
there are now 3 users
78+
```
79+
80+
## Common gotchas
81+
82+
:::warning
83+
84+
Deno reports `Unsupported compiler options in tsconfig.json` for a few options the scaffold sets for Node compatibility. The warning is harmless: Deno ignores those options and runs the code the same way.
85+
86+
:::
87+
88+
## Prompt your coding agent
89+
90+
The scaffold installs Prisma Next skills for your coding agent. Prompts that map to this guide:
91+
92+
- "Using the prisma-next-queries skill, add a Deno task that prints every user created in the last day."
93+
- "Tighten the Deno permissions for this project from -A to an explicit allow list."
94+
95+
## Next steps
96+
97+
- [Read the Prisma Next overview](/orm/next) for the concepts behind contracts and typed queries.
98+
- [Use the Bun guide](/guides/next/bun) if you also target Bun; the flow is the same apart from the runtime differences above.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: How to use Prisma Next with Hono
3+
description: Build a Hono API on Prisma Next with the hono template, then add your own routes.
4+
url: /guides/next/hono
5+
metaTitle: How to use Prisma Next with Hono
6+
metaDescription: Scaffold a Hono API backed by Prisma Next and Prisma Postgres, seed it, serve users over HTTP, and add a POST route, with tested commands and output.
7+
badge: early-access
8+
---
9+
10+
## Introduction
11+
12+
In this guide, you scaffold a Hono API backed by Prisma Next, initialize and seed a PostgreSQL database, serve data over HTTP, and add your own POST route. The `hono` template generates the server for you, so most of the work is understanding the pieces and extending them.
13+
14+
Every command, route, and response below was run end to end against a live Prisma Postgres database.
15+
16+
## Prerequisites
17+
18+
- Node.js 24 or later, or [Bun](https://bun.sh/) (this guide uses Bun for speed; npm works the same)
19+
- A PostgreSQL connection string, or nothing at all: the scaffold can create a [Prisma Postgres](/postgres) database for you
20+
21+
## 1. Scaffold the project
22+
23+
```bash
24+
bunx create-prisma@next create my-hono-api --provider postgres --template hono
25+
```
26+
27+
Pick your package manager and database at the prompts. The template generates a Hono server in `src/index.ts` with two routes (`GET /` and `GET /users`), the Prisma Next setup in `src/prisma/`, and package scripts for the database steps.
28+
29+
```bash
30+
cd my-hono-api
31+
```
32+
33+
## 2. Update the starter query helpers
34+
35+
Model access is namespace-qualified on PostgreSQL (`db.orm.public.User`), and the current template's helper files still use the older flat form, which fails at runtime. Open `src/prisma/users.ts` and `src/prisma/seed.ts` and change every `db.orm.User` to `db.orm.public.User`:
36+
37+
```ts title="src/prisma/users.ts"
38+
const users = await db.orm.public.User
39+
.select("id", "email", "username", "name", "createdAt")
40+
.take(limit)
41+
.all();
42+
```
43+
44+
:::note
45+
46+
This is a known template issue and will disappear from this guide once the template is updated.
47+
48+
:::
49+
50+
## 3. Initialize and seed the database
51+
52+
```bash
53+
bun run db:init
54+
bun run db:seed
55+
```
56+
57+
```text no-copy
58+
"summary": "Applied 5 operation(s) across 1 space(s), database signed"
59+
Seeded 3 users.
60+
```
61+
62+
## 4. Run the server
63+
64+
```bash
65+
bun run dev
66+
```
67+
68+
The server starts on port 3000 (set `PORT` to change it). Check both routes:
69+
70+
```bash
71+
curl http://localhost:3000/users
72+
```
73+
74+
```json no-copy
75+
[
76+
{ "id": "1", "email": "alice@prisma.io", "username": "alice", "name": "Alice", "createdAt": "2026-07-06T23:37:32.440Z" },
77+
{ "id": "2", "email": "bob@prisma.io", "username": "bob", "name": "Bob", "createdAt": "2026-07-06T23:37:32.474Z" },
78+
{ "id": "3", "email": "carol@prisma.io", "username": "carol", "name": "Carol", "createdAt": "2026-07-06T23:37:32.507Z" }
79+
]
80+
```
81+
82+
The route handler is ordinary Hono code calling an ordinary Prisma Next query; there is no framework adapter in between.
83+
84+
## 5. Add a POST route
85+
86+
Add a route that creates a user from the request body. Add this to `src/index.ts` above the `serve(...)` call:
87+
88+
```ts title="src/index.ts"
89+
app.post("/users", async (c) => {
90+
const body = await c.req.json<{ email: string; name?: string }>();
91+
const { db } = await import("./prisma/db");
92+
const user = await db.orm.public.User.create({
93+
email: body.email,
94+
name: body.name ?? null,
95+
});
96+
return c.json(user, 201);
97+
});
98+
```
99+
100+
Restart the server and create a user:
101+
102+
```bash
103+
curl -X POST http://localhost:3000/users \
104+
-H "content-type: application/json" \
105+
-d '{"email":"dev@prisma.io","name":"Dev"}'
106+
```
107+
108+
```json no-copy
109+
{ "createdAt": "2026-07-06T23:37:56.184Z", "email": "dev@prisma.io", "id": 4, "name": "Dev", "username": null }
110+
```
111+
112+
`.create(...)` returns the full inserted record, database defaults included, so the response needs no second query.
113+
114+
## Common gotchas
115+
116+
:::warning
117+
118+
In a long-running server, don't call `db.close()` in route handlers; the client's connection pool is shared across requests. Close it only on process shutdown.
119+
120+
:::
121+
122+
## Prompt your coding agent
123+
124+
The scaffold installs Prisma Next skills for your coding agent. Prompts that map to this guide:
125+
126+
- "Using the prisma-next-queries skill, add GET /users/:id that returns one user or a 404."
127+
- "Add a Post model related to User, update the database, and expose GET /users/:id/posts."
128+
- "Wrap the signup route's writes in a transaction."
129+
130+
## Next steps
131+
132+
- [Read the Prisma Next overview](/orm/next) for the concepts behind contracts and typed queries.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Prisma Next guides
3+
description: Start-to-finish guides for building with Prisma Next, converted from the Prisma 7 guides as each one is tested.
4+
url: /guides/next
5+
metaTitle: Prisma Next guides
6+
metaDescription: Hands-on Prisma Next guides for runtimes and frameworks, with tested examples. More groups land incrementally, including deployment, testing, and migration.
7+
badge: early-access
8+
---
9+
10+
These guides take you from an empty directory to a working result with Prisma Next. Every command and code sample in a published guide was run end to end against a live database before it landed here.
11+
12+
Use the version dropdown in the sidebar to switch between these guides and the Prisma 7 guides. The Prisma 7 versions stay where they are until Prisma Next becomes the default.
13+
14+
## Available now
15+
16+
<Cards>
17+
<Card href="/guides/next/bun" title="Bun" icon={<Zap className="text-primary" />}>
18+
Scaffold a Prisma Next app with Bun, initialize Prisma Postgres, and run your first typed query.
19+
</Card>
20+
<Card href="/guides/next/deno" title="Deno" icon={<Terminal className="text-primary" />}>
21+
Run Prisma Next on Deno, including the import and permission differences that matter.
22+
</Card>
23+
<Card href="/guides/next/hono" title="Hono" icon={<Flame className="text-primary" />}>
24+
Build a Hono API on Prisma Next with the hono template, and add your own routes.
25+
</Card>
26+
</Cards>
27+
28+
## Coming as they land
29+
30+
The guide groups follow the [Prisma Next docs plan](https://linear.app/prisma-company/issue/DR-8689/docs-guides-incremental-migration-deployment-performance-testing) and land one at a time, each tested before it ships:
31+
32+
- Migration: moving from Prisma 7, and between Prisma Next releases
33+
- Deployment: Vercel, Fly.io, AWS Lambda, Cloudflare Workers, Docker
34+
- Frameworks: Next.js, NestJS, SvelteKit, Astro, Nuxt, TanStack Start, Elysia
35+
- Testing: unit tests, integration tests, testing against the contract
36+
- Patterns, performance, and operations
37+
38+
Until a Prisma Next guide exists for your topic, the [Prisma 7 guide](/guides) still applies to Prisma 7 projects, and the [Prisma Next overview](/orm/next) covers the concepts any guide builds on.
39+
40+
## Next steps
41+
42+
- [Start with the quickstart](/next/quickstart/postgresql) if you don't have a Prisma Next project yet.
43+
- [Read the Prisma Next overview](/orm/next) for the concepts behind contracts, typed queries, and migrations.

0 commit comments

Comments
 (0)