Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import { definePrismaConfig } from "prisma/config";

export default definePrismaConfig({
composer: composer({
entry: "./module.ts",
extensions: [prismaCloud({ region: "us-east-1" }), nodeBuild()],
state: prismaState(),
}),
Expand All @@ -113,15 +114,15 @@ export default definePrismaConfig({

The module provisions a database and the API service and passes the database in as a dependency. `rawPostgres()` appears twice: with options in the module it creates the database, and bare in the service it declares what the service needs.

In the server, `service.load()` returns the database URL for whichever environment the code is running in. **The same file works on your laptop, in a preview, and in production without a connection string in any settings page**, and a dependency you forgot to wire is a type error. The `prisma.config.ts` file is read only by the CLI and names the extensions that deploy to Prisma and where deploy state is kept.
In the server, `service.load()` returns the database URL for whichever environment the code is running in. **The same file works on your laptop, in a preview, and in production without a connection string in any settings page**, and a dependency you forgot to wire is a type error. The `prisma.config.ts` file is read only by the CLI. Its `composer` section names the entry the CLI loads, `./module.ts`, along with the extensions that deploy to Prisma and where deploy state is kept.

A build script such as `bun build src/api/server.ts --target=bun --outfile dist/api/server.mjs` produces the file the service points at. The `node` build adapter is for Node.js-style servers, and Compute runs the output on Bun, so an Express or Hono server is declared the same way and runs through Bun's Node.js compatibility.

The `prisma` CLI you know from the ORM runs and deploys it, once the build has run:

- `npx prisma dev module.ts` runs the whole app on your machine against a local Postgres.
- `npx prisma deploy module.ts` provisions the real service and database, and running it again applies only what changed.
- `npx prisma deploy module.ts --stage <name>` deploys an isolated copy of the whole app, which is what the GitHub Action does for each preview branch.
- `npx prisma dev` runs the whole app on your machine against a local Postgres.
- `npx prisma deploy` provisions the real service and database, and running it again applies only what changed.
- `npx prisma deploy --environment <name>` deploys an isolated copy of the whole app. The GitHub Action does the same for each preview branch, with an environment named after the branch.

The example uses `rawPostgres()`, which hands your server a connection URL for whatever client you already use and leaves migrations to you. If your schema is managed by Prisma ORM 8, declare the database with `postgres()` and the data contract the ORM compiles from your schema instead: the server gets a client typed by that schema, and each deploy applies your migrations, which is what gives every preview database your schema from the start.

Expand Down Expand Up @@ -215,7 +216,7 @@ npm pkg set type=module
npm pkg set scripts.build="bun build src/api/server.ts --target=bun --outfile dist/api/server.mjs"
npx prisma auth login
npm run build
npx prisma deploy module.ts
npx prisma deploy
```

With the `tsconfig.json` from the [Composer getting-started guide](https://www.prisma.io/docs/composer/getting-started), `typescript` and `@types/bun` let `npx tsc --noEmit` check the wiring.
Expand All @@ -236,3 +237,4 @@ Tell us what you build, and what gets in the way, in the `prisma-compute` channe

- 2026-10-30: "What changed since the public beta" and "You pay for what your app runs" now say a paid plan's hard spend limit is one you set in the Console, with none until you set one, and that it caps usage charges in a billing cycle. Source: Prisma's [billing docs](https://www.prisma.io/docs/console/more/billing#cap-usage-charges-with-a-spending-limit), checked 2026-10-30.
- 2026-11-09: "You pay for what your app runs" now says a spend limit counts usage charges in a billing cycle and stops queries to the workspace's databases when it is reached. Source: Prisma's [billing docs](https://www.prisma.io/docs/console/more/billing#cap-usage-charges-with-a-spending-limit), checked 2026-11-09.
- 2026-11-09: the `npx prisma dev` and `npx prisma deploy` commands no longer name `module.ts`, because the CLI now reads the entry from the `composer` section of `prisma.config.ts`, and the example `prisma.config.ts` now sets it with `entry: "./module.ts"`. The isolated-copy command uses `--environment <name>`, which replaced `--stage <name>`. Source: Prisma's [`deploy` reference](https://www.prisma.io/docs/cli/deploy), checked 2026-11-09.
9 changes: 5 additions & 4 deletions apps/blog/content/blog/prisma-orm-8-nestjs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "The new way to use Prisma ORM 8 in NestJS"
slug: "prisma-orm-8-nestjs"
date: "2026-09-24"
updatedAt: "2026-10-23"
updatedAt: "2026-11-09"
authors:
- "Ankur Datta"
metaTitle: "How to use Prisma ORM 8 in NestJS: setup, queries, deploy"
Expand All @@ -18,7 +18,7 @@ seriesIndex: 15

[Prisma ORM 8](https://www.prisma.io/docs/orm), the new major version of Prisma's TypeScript ORM, changes how you wire the client into [NestJS](https://nestjs.com). The Prisma ORM 8 client is a plain object exported by `src/prisma/db.ts`, so there is no class to extend, and the NestJS template that `create-prisma` scaffolds has no service that extends `PrismaClient`. One shared client lives in `src/prisma/db.ts`, and an injectable `PrismaService` exposes query helpers written as ordinary functions. Prisma ORM 8 is the version npm installs by default.

This post is the fifteenth in our Prisma 8 series, following [Is Prisma 8 ready for long-lived production apps?](/is-prisma-8-ready-for-long-lived-production-apps). It walks through scaffolding a NestJS API on [Prisma Postgres](https://www.prisma.io/docs/postgres), following a request from the controller to the database, writing typed queries, and deploying the API to [Prisma Compute](https://www.prisma.io/docs/compute). We ran every command below against `prisma@8.0.0-rc.15`, `@prisma/orm-postgres@8.0.0-rc.11`, and NestJS 11.
This post is the fifteenth in our Prisma 8 series, following [Is Prisma 8 ready for long-lived production apps?](/is-prisma-8-ready-for-long-lived-production-apps). It walks through scaffolding a NestJS API on [Prisma Postgres](https://www.prisma.io/docs/postgres), following a request from the controller to the database, writing typed queries, and deploying the API to [Prisma Compute](https://www.prisma.io/docs/compute). We ran every command below against `prisma@8.0.0-rc.15`, `@prisma/orm-postgres@8.0.0-rc.11`, and NestJS 11, except the deploy command, which is shown in the form that `prisma@8.0.0-rc.28` and later accept.

## Share your client without extending it

Expand Down Expand Up @@ -239,10 +239,10 @@ The scaffold includes `module.ts` and `service.ts`, which describe the app and i
```bash
npx prisma auth login
npm run build
npx prisma deploy module.ts
npx prisma deploy
```

`prisma auth login` opens the browser once. `npm run build` bundles the app with `tsdown` into `dist/server.mjs`. `prisma deploy module.ts` provisions the database and the compute service and prints the app URL. `npm run deploy` runs the last two together.
`prisma auth login` opens the browser once, and `npm run build` bundles the app with `tsdown` into `dist/server.mjs`. `prisma deploy` provisions the database and the compute service and prints the app URL. It takes no file name: since `prisma@8.0.0-rc.28`, the CLI reads the entry from the `composer` section of `prisma.config.ts`, which the scaffold sets to `./module.ts`. `npm run deploy` runs the last two together.

```text
nest-prisma-8
Expand Down Expand Up @@ -308,3 +308,4 @@ Try Prisma ORM 8 in your NestJS app and tell us what works well or where you get
## Update history

- 2026-10-23: clarified that claiming a create-db database to keep it requires a free Prisma account.
- 2026-11-09: the deploy step runs `npx prisma deploy` without `module.ts`, because since `prisma@8.0.0-rc.28` the CLI reads the entry from the `composer` section of `prisma.config.ts`, which the `create-prisma` scaffold sets to `./module.ts`; the note on the versions we ran now says the deploy command is shown in that form.
9 changes: 5 additions & 4 deletions apps/blog/content/blog/prisma-vs-netlify/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ For the availability date in the first row and the FAQ, checked 2026-11-02: the

Compute runs your Node.js, Bun or Next.js server on Bun, as an instance that scales to zero when idle. Only the first byte of a response has a deadline: it must go out within 60 seconds, and a streamed response keeps going after that. `waitUntil` keeps the instance awake to finish work after the response is sent, on a best-effort basis. Compute does not run WebSocket servers today (support is planned for early 2027), and each service runs in one region.

**Netlify is the better fit** when your app is mostly pages and assets served from its edge network, or when you want every preview to start with a copy of production data. On Prisma, a preview's database is created by you or by a Composer stage deploy, and it starts *empty*.
**Netlify is the better fit** when your app is mostly pages and assets served from its edge network, or when you want every preview to start with a copy of production data. On Prisma, a preview's database is created by you or by a Composer deploy of the branch, and it starts *empty*.

## Why teams leave Netlify

Expand Down Expand Up @@ -308,7 +308,7 @@ Netlify has no concept of one deployed service calling another. If your backend
2. **Give each service a contract**, meaning typed request and response schemas written with arktype, zod, or any Standard Schema validator.
3. **Declare the contracts a service calls** as its dependencies. At runtime the service receives a typed client for each one.
4. **Wire everything in a root module.** TypeScript checks the wiring, so binding a dependency to a service with a different contract, or leaving out a handler the contract requires, is a compile error.
5. **Run `npx prisma deploy module.ts`**, or push once the deploy workflow is committed. It creates the services on Prisma Compute, the databases on Prisma Postgres, and the authenticated connections between them. Application code never builds a URL from `process.env`.
5. **Run `npx prisma deploy`**, or push once the deploy workflow is committed. The CLI loads the root module named by `entry` in the `composer` section of `prisma.config.ts`, such as `./module.ts`; a push deploy instead uses the deploy action's `module` input, which defaults to `module.ts`, so set that input if your entry lives elsewhere. The deploy creates the services on Prisma Compute, the databases on Prisma Postgres, and the authenticated connections between them. Application code never builds a URL from `process.env`.

![What each platform connects: on Prisma, the repository holds the data contract, the service contract, and the root module; prisma deploy provisions the storefront and catalog services on Prisma Compute and a Prisma Postgres database typed by the contract. On Netlify, the repository holds the site and its functions; a git push builds and publishes both, and Netlify Database connects a Postgres branch per preview through NETLIFY_DB_URL.](/prisma-vs-netlify/imgs/what-each-platform-connects.svg)

Expand Down Expand Up @@ -358,7 +358,7 @@ Both platforms can give every branch other than the production branch a running
4. Redeploy the branch so it picks up the new `DATABASE_URL`, because variables are resolved at deploy time and changing one does not trigger a redeploy.
5. Seed it if the feature needs realistic rows, because it starts empty.

With Composer, the deploy action deploys each pushed branch other than the default one as a stage, and `npx prisma deploy module.ts --stage <branch>` does the same from your terminal. A stage deploy replaces the first four steps: it creates the databases the module declares, passes each service its connection, and applies the committed migrations of each `postgres()` database before the services start. Those databases still start empty, because preview data is not copied from production.
With Composer, the deploy action deploys each pushed branch other than the default one as an environment named after the branch, and `npx prisma deploy --environment <branch>` does the same from your terminal. That deploy replaces the first four steps: it creates the databases the module declares, passes each service its connection, and applies the committed migrations of each `postgres()` database before the services start. Those databases still start empty, because preview data is not copied from production.

A preview uses whatever `DATABASE_URL` its preview scope or branch override gives it, so if that value is the production connection string, the preview *writes to production*. Keep production and preview values in separate scopes, as the [environment variables docs](https://www.prisma.io/docs/compute/environment-variables) describe.

Expand Down Expand Up @@ -447,7 +447,7 @@ Prisma Compute runs a server, not separate functions. It runs your whole HTTP se
Prisma replaces part of what Netlify does. For a TypeScript app built for Node.js, Bun or Next.js, Prisma Compute can host the app and its API on Bun, and Prisma Postgres can replace Netlify Database. Prisma does not replace Netlify's edge network, caching, Image CDN, or Identity. Compute has no WebSocket servers today (support is planned for early 2027), runs each service in one region, and gives a request 60 seconds to start responding.
</Accordion>
<Accordion title="Does Prisma give each preview its own database?">
Each preview gets its own database once you or a Composer stage deploy create it, and that database starts without production data. Each Git branch is an isolated environment. With Composer, the stage deploy creates the database, applies its migrations, and passes the connection to your services. Without Composer, you create the database with the CLI, point a preview-scoped or branch-scoped `DATABASE_URL` at it, apply your migrations, and redeploy, and that separate `DATABASE_URL` keeps the preview off production.
Each preview gets its own database once you create it or a Composer deploy of the branch does, and that database starts without production data. Each Git branch is an isolated environment. With Composer, the deploy of the branch creates the database, applies its migrations, and passes the connection to your services. Without Composer, you create the database with the CLI, point a preview-scoped or branch-scoped `DATABASE_URL` at it, apply your migrations, and redeploy, and that separate `DATABASE_URL` keeps the preview off production.
</Accordion>
<Accordion title="What is the migration graph in Prisma ORM 8?">
The migration graph is a record of which schema version each migration starts from and produces. After two branches merge, you plan one migration to the merged schema, and `db migrate` follows the recorded migrations from each deployed database's current version to reach it. A development database left on a pre-merge state is brought to the merged schema with `db update`. It is an ORM feature and works on any host, including Netlify.
Expand Down Expand Up @@ -488,6 +488,7 @@ Prisma ORM works with Netlify Database, which is PostgreSQL built on Neon, and i

## Update history

- 2026-11-09: step 5 of "What each platform sets up for you" now runs `npx prisma deploy` and says the CLI loads the root module named by `entry` in the `composer` section of `prisma.config.ts`, while a push deploy takes it from the deploy action's `module` input; "Previews and their databases" now names the terminal command `npx prisma deploy --environment <branch>`, because `--environment` replaced `--stage`; and the paragraph under "Pick by app type" and the FAQ on preview databases say "a Composer deploy of the branch" in place of "a Composer stage deploy". Sources: Prisma's [`deploy` reference](https://www.prisma.io/docs/cli/deploy) and the [deploy action's inputs](https://github.com/prisma/cloud-deploy-action#inputs), checked 2026-11-09.
- 2026-11-09: a new FAQ entry covers whether the Node.js APIs and npm packages an app relies on work on Prisma Compute's Bun runtime and how to check before moving, from the Compute docs; the "Usage-based bill you need to cap" row now lists Prisma Postgres with a spend limit set, and that row and "Why teams leave Netlify" now say the limit counts usage charges, not the plan fee, and stops queries to the workspace's databases when it is reached; and the "The bill stopped being predictable" bullet now says usage-metered hosts differ in what a limit stops, in place of how they cap the bill. Checked against Prisma's [billing docs](https://www.prisma.io/docs/console/more/billing#cap-usage-charges-with-a-spending-limit), [Compute FAQ](https://www.prisma.io/docs/compute/faq), [Compute limitations](https://www.prisma.io/docs/compute/limitations) and [local development docs](https://www.prisma.io/docs/local-development/app-development) on 2026-11-09.
- 2026-11-08: the summary under the title now says Prisma Compute has been generally available since August 2026; the Vercel profile now says Vercel Postgres is no longer available and new projects add Postgres from the Vercel Marketplace, where Prisma Postgres, Neon and Supabase are listed; and the Fly.io "Best for" line now says a Fly.io Managed Postgres cluster runs in the one region you choose. Checked against Vercel's [Postgres docs](https://vercel.com/docs/postgres) and [Marketplace storage docs](https://vercel.com/docs/marketplace-storage), and Fly.io's [cluster docs](https://docs.fly.io/postgres/create-and-connect/), on 2026-11-06.
- 2026-11-06: the free-plan row of "Pick by app type" now gives Fly.io's free trial for new accounts as $1 of credit for Machines, Sprites and Managed Postgres, which lasts 7 days or until it is used up, with no credit card needed, in place of the earlier trial terms; and the list of what "Prisma" means in this post now says the ORM is optional. Checked against Fly.io's [pricing docs](https://docs.fly.io/about/pricing/) on 2026-11-06.
Expand Down
Loading
Loading