-
Notifications
You must be signed in to change notification settings - Fork 957
docs(guides): Prisma Next guides with a Guides version dropdown (DR-8689) #8022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c8ab87
docs(guides): add Prisma Next guides with a Guides version dropdown (…
ankur-arch 47e18d9
docs(guides): mirror the Prisma 7 folder structure, add tested Elysia…
ankur-arch c2be4fd
docs(guides): assume fixed scaffold templates; keep a fallback note
ankur-arch 1d9868d
docs(guides): all framework templates tested and converted, latest-st…
ankur-arch f5778a6
Merge main (Fundamentals #8011); combine cutover comment blocks
ankur-arch 92a34f3
docs(guides): cross-link the merged Fundamentals section; clarify mig…
ankur-arch 58e127a
Merge remote-tracking branch 'origin/main' into pn-guides-DR-8689
nurul3101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| "icon": "NotebookTabs", | ||
| "pages": [ | ||
| "index", | ||
| "next", | ||
| "frameworks", | ||
| "runtimes", | ||
| "deployment", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| --- | ||
| title: Astro | ||
| description: Set up Prisma Next in a Astro app with create-prisma, from scaffold to rendered data. | ||
| url: /guides/next/frameworks/astro | ||
| metaTitle: How to use Prisma Next with Astro | ||
| metaDescription: Scaffold a Astro project with Prisma Next and Prisma Postgres, initialize the database, seed it, and see your data, with tested commands. | ||
| --- | ||
|
|
||
| ## Introduction | ||
|
|
||
| This guide shows you how to use Prisma Next in an Astro site. You scaffold a project that queries users during server rendering and exposes a JSON API route, initialize the schema, and see your data render. | ||
|
|
||
| Every command below was run end to end against a live [Prisma Postgres](/postgres) database. | ||
|
|
||
| ## Quick start | ||
|
|
||
| One command scaffolds the project with Prisma Next wired in: | ||
|
|
||
| ```npm | ||
| npx create-prisma@next --template astro --provider postgres | ||
| ``` | ||
|
|
||
| Pick Prisma Postgres at the database prompt to have a database created for you, or paste your own `DATABASE_URL`. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Node.js](https://nodejs.org) v20.19 or later | ||
| - A PostgreSQL connection string, or nothing at all: the scaffold can create the database for you | ||
|
|
||
| ## 1. Scaffold and enter the project | ||
|
|
||
| ```npm | ||
| npx create-prisma@next --template astro --provider postgres | ||
| cd my-app | ||
| ``` | ||
|
|
||
| The scaffold writes your connection string to `.env`, generates the Astro app with Prisma Next wired in, installs dependencies, and emits the contract your queries are type-checked against. | ||
|
|
||
| ## 2. Initialize and seed the database | ||
|
|
||
| ```npm | ||
| npm run db:init | ||
| npm run db:seed | ||
| ``` | ||
|
|
||
| ```text no-copy | ||
| "summary": "Applied 5 operation(s) across 1 space(s), database signed" | ||
| Seeded 3 users. | ||
| ``` | ||
|
|
||
| `db:init` applies your schema (`src/prisma/contract.prisma`) to the database and signs it; the seed gives the first page something to show. | ||
|
|
||
| ## 3. Run and verify | ||
|
|
||
| ```npm | ||
| npm run dev | ||
| ``` | ||
|
|
||
| Open [http://localhost:4321](http://localhost:4321). The page lists the seeded users; `GET /api/users` returns them as JSON. | ||
|
|
||
| ## Where things live | ||
|
|
||
| - `src/pages/index.astro`: queries users in the frontmatter and renders them | ||
| - `src/pages/api/users.ts`: a JSON API route backed by the same query | ||
| - `src/prisma/db.ts`: the Prisma Next client both import | ||
|
|
||
| Model access is namespace-qualified on PostgreSQL: `db.orm.public.User`. The [Prisma Next overview](/orm/next) covers the contract-first model behind it. | ||
|
|
||
| ## Next steps | ||
|
|
||
| - Change the schema in `src/prisma/contract.prisma`, then run `npm run contract:emit` and `npm run db:update`. | ||
| - [Learn the fundamentals](/orm/next/fundamentals/reading-data): filtering, sorting, pagination, and writes. | ||
| - [Read the Prisma Next overview](/orm/next) for the concepts behind contracts and typed queries. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| title: Elysia | ||
| description: Build an Elysia API on Prisma Next with the elysia template. | ||
| url: /guides/next/frameworks/elysia | ||
| metaTitle: How to use Prisma Next with Elysia | ||
| metaDescription: Scaffold an Elysia API backed by Prisma Next and Prisma Postgres, seed it, and serve users over HTTP, with tested commands and output. | ||
| --- | ||
|
|
||
| ## Introduction | ||
|
|
||
| In this guide, you scaffold an Elysia API backed by Prisma Next, initialize and seed a PostgreSQL database, and serve data over HTTP. The `elysia` template generates the server, so most of the work is understanding the pieces. | ||
|
|
||
| Every command and response below was run end to end against a live Prisma Postgres database. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Bun](https://bun.sh/) 1.1 or later (Elysia is Bun-first) | ||
| - A PostgreSQL connection string, or nothing at all: the scaffold can create a [Prisma Postgres](/postgres) database for you | ||
|
|
||
| ## 1. Scaffold the project | ||
|
|
||
| ```bash | ||
| bunx create-prisma@next create my-elysia-api --provider postgres --template elysia | ||
| ``` | ||
|
|
||
| Pick your database at the prompt. The template generates an Elysia server in `src/index.ts` with `GET /` and `GET /users` routes, the Prisma Next setup in `src/prisma/`, and package scripts for the database steps. | ||
|
|
||
| ```bash | ||
| cd my-elysia-api | ||
| ``` | ||
|
|
||
| ## 2. Initialize and seed the database | ||
|
|
||
| ```bash | ||
| bun run db:init | ||
| bun run db:seed | ||
| ``` | ||
|
|
||
| ```text no-copy | ||
| "summary": "Applied 5 operation(s) across 1 space(s), database signed" | ||
| Seeded 3 users. | ||
| ``` | ||
|
|
||
| :::note | ||
|
|
||
| Scaffolded with an older `create-prisma` and seeing `Cannot read properties of undefined (reading 'where')`? Update `db.orm.User` to `db.orm.public.User` in `src/prisma/seed.ts` and `src/prisma/users.ts`. Current templates generate the qualified form. | ||
|
|
||
| ::: | ||
|
|
||
| ## 3. Run the server | ||
|
|
||
| ```bash | ||
| bun run dev | ||
| ``` | ||
|
|
||
| The server starts on port 3000 (set `PORT` to change it): | ||
|
|
||
| ```bash | ||
| curl http://localhost:3000/users | ||
| ``` | ||
|
|
||
| ```json no-copy | ||
| [ | ||
| { "id": "1", "email": "alice@prisma.io", "username": "alice", "name": "Alice", "createdAt": "2026-07-07T08:51:14.054Z" }, | ||
| { "id": "2", "email": "bob@prisma.io", "username": "bob", "name": "Bob", "createdAt": "2026-07-07T08:51:14.089Z" }, | ||
| { "id": "3", "email": "carol@prisma.io", "username": "carol", "name": "Carol", "createdAt": "2026-07-07T08:51:14.122Z" } | ||
| ] | ||
| ``` | ||
|
|
||
| The route handler is ordinary Elysia code calling an ordinary Prisma Next query; there is no framework adapter in between. To add write routes, follow the same pattern as the [Hono guide's POST route](/guides/next/frameworks/hono#4-add-a-post-route); the query code is identical. | ||
|
|
||
| ## Common gotchas | ||
|
|
||
| :::warning | ||
|
|
||
| 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. | ||
|
|
||
| ::: | ||
|
|
||
| ## Prompt your coding agent | ||
|
|
||
| The scaffold installs Prisma Next skills for your coding agent. Prompts that map to this guide: | ||
|
|
||
| - "Using the prisma-next-queries skill, add GET /users/:id that returns one user or a 404." | ||
| - "Add a POST /users route that creates a user from the request body." | ||
|
|
||
| ## Next steps | ||
|
|
||
| - [Learn the fundamentals](/orm/next/fundamentals/reading-data): filtering, sorting, pagination, and writes. | ||
| - [Read the Prisma Next overview](/orm/next) for the concepts behind contracts and typed queries. | ||
| - [Use the Hono guide](/guides/next/frameworks/hono) for the tested POST route pattern. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| --- | ||
| title: Hono | ||
| description: Build a Hono API on Prisma Next with the hono template, then add your own routes. | ||
| url: /guides/next/frameworks/hono | ||
| metaTitle: How to use Prisma Next with Hono | ||
| 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. | ||
| --- | ||
|
|
||
| ## Introduction | ||
|
|
||
| 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. | ||
|
|
||
| Every command, route, and response below was run end to end against a live Prisma Postgres database. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js 24 or later, or [Bun](https://bun.sh/) (this guide uses Bun for speed; npm works the same) | ||
| - A PostgreSQL connection string, or nothing at all: the scaffold can create a [Prisma Postgres](/postgres) database for you | ||
|
|
||
| ## 1. Scaffold the project | ||
|
|
||
| ```bash | ||
| bunx create-prisma@next create my-hono-api --provider postgres --template hono | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| ```bash | ||
| cd my-hono-api | ||
| ``` | ||
|
|
||
| ## 2. Initialize and seed the database | ||
|
|
||
| ```bash | ||
| bun run db:init | ||
| bun run db:seed | ||
| ``` | ||
|
|
||
| ```text no-copy | ||
| "summary": "Applied 5 operation(s) across 1 space(s), database signed" | ||
| Seeded 3 users. | ||
| ``` | ||
|
|
||
| :::note | ||
|
|
||
| Scaffolded with an older `create-prisma` and seeing `Cannot read properties of undefined (reading 'where')`? Update `db.orm.User` to `db.orm.public.User` in `src/prisma/seed.ts` and `src/prisma/users.ts`. Current templates generate the qualified form. | ||
|
|
||
| ::: | ||
|
|
||
| ## 3. Run the server | ||
|
|
||
| ```bash | ||
| bun run dev | ||
| ``` | ||
|
|
||
| The server starts on port 3000 (set `PORT` to change it). Check both routes: | ||
|
|
||
| ```bash | ||
| curl http://localhost:3000/users | ||
| ``` | ||
|
|
||
| ```json no-copy | ||
| [ | ||
| { "id": "1", "email": "alice@prisma.io", "username": "alice", "name": "Alice", "createdAt": "2026-07-06T23:37:32.440Z" }, | ||
| { "id": "2", "email": "bob@prisma.io", "username": "bob", "name": "Bob", "createdAt": "2026-07-06T23:37:32.474Z" }, | ||
| { "id": "3", "email": "carol@prisma.io", "username": "carol", "name": "Carol", "createdAt": "2026-07-06T23:37:32.507Z" } | ||
| ] | ||
| ``` | ||
|
nurul3101 marked this conversation as resolved.
|
||
|
|
||
| The route handler is ordinary Hono code calling an ordinary Prisma Next query; there is no framework adapter in between. | ||
|
|
||
| ## 4. Add a POST route | ||
|
|
||
| Add a route that creates a user from the request body. Add this to `src/index.ts` above the `serve(...)` call: | ||
|
|
||
| ```ts title="src/index.ts" | ||
| app.post("/users", async (c) => { | ||
| const body = await c.req.json<{ email: string; name?: string }>(); | ||
| const { db } = await import("./prisma/db"); | ||
| const user = await db.orm.public.User.create({ | ||
| email: body.email, | ||
| name: body.name ?? null, | ||
| }); | ||
| return c.json(user, 201); | ||
| }); | ||
| ``` | ||
|
|
||
| Restart the server and create a user: | ||
|
|
||
| ```bash | ||
| curl -X POST http://localhost:3000/users \ | ||
| -H "content-type: application/json" \ | ||
| -d '{"email":"dev@prisma.io","name":"Dev"}' | ||
| ``` | ||
|
|
||
| ```json no-copy | ||
| { "createdAt": "2026-07-06T23:37:56.184Z", "email": "dev@prisma.io", "id": 4, "name": "Dev", "username": null } | ||
| ``` | ||
|
|
||
| `.create(...)` returns the full inserted record, database defaults included, so the response needs no second query. | ||
|
|
||
| ## Common gotchas | ||
|
|
||
| :::warning | ||
|
|
||
| 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. | ||
|
|
||
| ::: | ||
|
|
||
| ## Prompt your coding agent | ||
|
|
||
| The scaffold installs Prisma Next skills for your coding agent. Prompts that map to this guide: | ||
|
|
||
| - "Using the prisma-next-queries skill, add GET /users/:id that returns one user or a 404." | ||
| - "Add a Post model related to User, update the database, and expose GET /users/:id/posts." | ||
| - "Wrap the signup route's writes in a [transaction](/orm/next/fundamentals/transactions)." | ||
|
|
||
| ## Next steps | ||
|
|
||
| - [Learn the fundamentals](/orm/next/fundamentals/reading-data): filtering, sorting, pagination, and writes. | ||
| - [Read the Prisma Next overview](/orm/next) for the concepts behind contracts and typed queries. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "title": "Frameworks", | ||
| "defaultOpen": true, | ||
| "pages": [ | ||
| "nextjs", | ||
| "astro", | ||
| "nuxt", | ||
| "sveltekit", | ||
| "tanstack-start", | ||
| "nestjs", | ||
| "hono", | ||
| "elysia" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| title: NestJS | ||
| description: Set up Prisma Next in a NestJS app with create-prisma, from scaffold to rendered data. | ||
| url: /guides/next/frameworks/nestjs | ||
| metaTitle: How to use Prisma Next with NestJS | ||
| metaDescription: Scaffold a NestJS project with Prisma Next and Prisma Postgres, initialize the database, seed it, and see your data, with tested commands. | ||
| --- | ||
|
|
||
| ## Introduction | ||
|
|
||
| This guide shows you how to use Prisma Next in a NestJS API. You scaffold a project with a users controller backed by Prisma Next, initialize the schema, and query it over HTTP. | ||
|
|
||
| Every command below was run end to end against a live [Prisma Postgres](/postgres) database. | ||
|
|
||
| ## Quick start | ||
|
|
||
| One command scaffolds the project with Prisma Next wired in: | ||
|
|
||
| ```npm | ||
| npx create-prisma@next --template nest --provider postgres | ||
| ``` | ||
|
|
||
| Pick Prisma Postgres at the database prompt to have a database created for you, or paste your own `DATABASE_URL`. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Node.js](https://nodejs.org) v20.19 or later | ||
| - A PostgreSQL connection string, or nothing at all: the scaffold can create the database for you | ||
|
|
||
| ## 1. Scaffold and enter the project | ||
|
|
||
| ```npm | ||
| npx create-prisma@next --template nest --provider postgres | ||
| cd my-app | ||
| ``` | ||
|
|
||
| The scaffold writes your connection string to `.env`, generates the NestJS app with Prisma Next wired in, installs dependencies, and emits the contract your queries are type-checked against. | ||
|
|
||
| ## 2. Initialize and seed the database | ||
|
|
||
| ```npm | ||
| npm run db:init | ||
| npm run db:seed | ||
| ``` | ||
|
|
||
| ```text no-copy | ||
| "summary": "Applied 5 operation(s) across 1 space(s), database signed" | ||
| Seeded 3 users. | ||
| ``` | ||
|
nurul3101 marked this conversation as resolved.
|
||
|
|
||
| `db:init` applies your schema (`src/prisma/contract.prisma`) to the database and signs it; the seed gives the first page something to show. | ||
|
nurul3101 marked this conversation as resolved.
|
||
|
|
||
| ## 3. Run and verify | ||
|
|
||
| ```npm | ||
| npm run dev | ||
| ``` | ||
|
|
||
| Query the API: | ||
|
|
||
| ```bash | ||
| curl http://localhost:3000/users | ||
| ``` | ||
|
|
||
| ```json no-copy | ||
| [ | ||
| { "id": "1", "email": "alice@prisma.io", "username": "alice", "name": "Alice", "createdAt": "2026-07-07T09:44:19.201Z" } | ||
| ] | ||
| ``` | ||
|
|
||
| ## Where things live | ||
|
|
||
| - `src/users.controller.ts`: the `GET /users` route | ||
| - `src/users.service.ts`: the service that runs the Prisma Next query | ||
| - `src/prisma/db.ts`: the Prisma Next client the service imports | ||
|
|
||
| Model access is namespace-qualified on PostgreSQL: `db.orm.public.User`. The [Prisma Next overview](/orm/next) covers the contract-first model behind it. | ||
|
|
||
| ## Next steps | ||
|
|
||
| - Change the schema in `src/prisma/contract.prisma`, then run `npm run contract:emit` and `npm run db:update`. | ||
| - [Learn the fundamentals](/orm/next/fundamentals/reading-data): filtering, sorting, pagination, and writes. | ||
| - [Read the Prisma Next overview](/orm/next) for the concepts behind contracts and typed queries. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.