Skip to content
Merged
1 change: 1 addition & 0 deletions apps/docs/content/docs/guides/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"icon": "NotebookTabs",
"pages": [
"index",
"next",
"frameworks",
"runtimes",
"deployment",
Expand Down
73 changes: 73 additions & 0 deletions apps/docs/content/docs/guides/next/frameworks/astro.mdx
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.
91 changes: 91 additions & 0 deletions apps/docs/content/docs/guides/next/frameworks/elysia.mdx
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.
121 changes: 121 additions & 0 deletions apps/docs/content/docs/guides/next/frameworks/hono.mdx
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
```
Comment thread
nurul3101 marked this conversation as resolved.

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" }
]
```
Comment thread
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.
14 changes: 14 additions & 0 deletions apps/docs/content/docs/guides/next/frameworks/meta.json
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"
]
}
83 changes: 83 additions & 0 deletions apps/docs/content/docs/guides/next/frameworks/nestjs.mdx
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.
```
Comment thread
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.
Comment thread
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.
Loading
Loading