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 @@ -10,6 +10,15 @@ This page introduces one-to-one relations and explains how to use them in your P

</TopBlock>

<details>
<summary>Questions answered in this page</summary>

- How do I model one-to-one relations?
- Which side should store the foreign key?
- How do optional vs required 1-1 work?

</details>

## Overview

One-to-one (1-1) relations refer to relations where at most **one** record can be connected on both sides of the relation. In the example below, there is a one-to-one relation between `User` and `Profile`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ tocDepth: 3

This page introduces one-to-many relations and explains how to use them in your Prisma schema.

<details>
<summary>Questions answered in this page</summary>

- How do I model one-to-many relations?
- Which side holds the foreign key in 1-n?
- How do optional vs required 1-n work?

</details>

## Overview

One-to-many (1-n) relations refer to relations where one record on one side of the relation can be connected to zero or more records on the other side. In the following example, there is one one-to-many relation between the `User` and `Post` models:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Prisma schema syntax and the implementation in the underlying database differs b

</TopBlock>

<details>
<summary>Questions answered in this page</summary>

- How do I model many-to-many in Prisma?
- When to use implicit vs explicit m-n?
- How do I query m-n relations?

</details>

## Relational databases

In relational databases, m-n-relations are typically modelled via [relation tables](/orm/prisma-schema/data-model/relations/many-to-many-relations#relation-tables). m-n-relations can be either [explicit](#explicit-many-to-many-relations) or [implicit](#implicit-many-to-many-relations) in the Prisma schema. We recommend using [implicit](#implicit-many-to-many-relations) m-n-relations if you do not need to store any additional meta-data in the relation table itself. You can always migrate to an [explicit](#explicit-many-to-many-relations) m-n-relation later if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ metaDescription: How to define and work with self-relations in Prisma.

A relation field can also reference its own model, in this case the relation is called a _self-relation_. Self-relations can be of any cardinality, 1-1, 1-n and m-n.

<details>
<summary>Questions answered in this page</summary>

- How do I model self-relations?
- Do self-relations always require @relation?
- How do 1-1 vs 1-n self-relations differ?

</details>

Note that self-relations always require the `@relation` attribute.

## One-to-one self-relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ In more complicated data models, finding the cascade paths can get complex. Ther

</TopBlock>

<details>
<summary>Questions answered in this page</summary>

- How do I fix cascade cycles on SQL Server?
- Do MongoDB self-relations require NoAction?
- How do I handle multiple cascade paths?

</details>

## Self-relation (SQL Server and MongoDB)

The following model describes a self-relation where an `Employee` can have a manager and managees, referencing entries of the same model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ If you do not specify a referential action, Prisma ORM [uses a default](#referen

</TopBlock>

<details>
<summary>Questions answered in this page</summary>

- What do referential actions do?
- Which defaults apply if none are set?
- How do actions map to my database?

</details>

<Admonition type="danger">

If you upgrade from a version earlier than 2.26.0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ metaDescription: 'Manage relations between records with relation modes in Prisma
tocDepth: 3
---

<details>
<summary>Questions answered in this page</summary>

- What is `relationMode` in Prisma?
- When should I use `prisma` vs `foreignKeys`?
- How does relation emulation affect constraints?

</details>

In Prisma schema, relations between records are defined with the [`@relation`](/orm/reference/prisma-schema-reference#relation) attribute. For example, in the following schema there is a one-to-many relation between the `User` and `Post` models:

```prisma file=schema.prisma highlight=4,5,10;normal showLineNumbers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ In most cases, you **do not need to explicitly call these methods**. `PrismaClie

See the [connection management guide](/orm/prisma-client/setup-and-configuration/databases-connections) for information about managing connections for different deployment paradigms (long-running processes and serverless functions).

<details>
<summary>Questions answered in this page</summary>

- When should I call $connect and $disconnect?
- How does Prisma manage connection pools?
- How to handle connections in serverless?

</details>

</TopBlock>

## `$connect()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ The query engine manages a **connection pool** of database connections. The pool

Relational database connectors use Prisma ORM's own connection pool, and the MongoDB connectors uses the [MongoDB driver connection pool](https://github.com/mongodb/specifications/blob/master/source/connection-monitoring-and-pooling/connection-monitoring-and-pooling.rst).

<details>
<summary>Questions answered in this page</summary>

- How do I size Prisma's connection pool?
- How do I set pool timeouts and limits?
- When should I use PgBouncer with Prisma?

</details>

:::note

As of [v6.16.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without Rust engines in production applications. Learn more [here](/orm/prisma-client/setup-and-configuration/no-rust-engine).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ An external connection pooler like PgBouncer holds a connection pool to the data

Usually, this works transparently, but some connection poolers only support a limited set of functionality. One common feature that external connection poolers do not support are named prepared statements, which Prisma ORM uses. For these cases, Prisma ORM can be configured to behave differently.

<details>
<summary>Questions answered in this page</summary>

- How do I configure Prisma with PgBouncer?
- Do I need `pgbouncer=true`, and if so, when?
- How does Prisma Migrate work with PgBouncer?

</details>

:::info

Looking for an easy, infrastructure-free solution? Try [Prisma Accelerate](https://www.prisma.io/accelerate?utm_source=docs&utm_campaign=pgbouncer-help)! It requires little to no setup and works seamlessly with all databases supported by Prisma ORM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ model Tag {

</TopBlock>

<details>
<summary>Questions answered in this page</summary>

- How to implement soft delete middleware?
- How to block reads/updates of deleted records?
- What are trade-offs of middleware-based soft delete?

</details>

## Step 1: Store status of record

Add a field named `deleted` to the `Post` model. You can choose between two field types depending on your requirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ metaDescription: 'Learn how to deploy a Node.js server that uses Prisma ORM to R

This guide explains how to deploy a Node.js server that uses Prisma ORM and PostgreSQL to Render.

<details>
<summary>Questions answered in this page</summary>

- How to deploy Prisma apps on Render?
- How to run migrations before start?
- What Render settings are recommended?

</details>

The [Prisma Render deployment example](https://github.com/prisma/prisma-examples/tree/latest/deployment-platforms/render) contains an Express.js application with REST endpoints and a simple frontend. This app uses Prisma Client to fetch, create, and delete records from its database.

## About Render
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ tocDepth: 3

This guide explains how to avoid common issues when deploying a project using Prisma ORM to [AWS Lambda](https://aws.amazon.com/lambda/).

<details>
<summary>Questions answered in this page</summary>

- How to deploy Prisma to AWS Lambda?
- Which binaryTargets should I configure?
- How to handle connection pooling on Lambda?

</details>

While a deployment framework is not required to deploy to AWS Lambda, this guide covers deploying with:

- [AWS Serverless Application Model (SAM)](https://aws.amazon.com/serverless/sam/) is an open-source framework from AWS that can be used in the creation of serverless applications. AWS SAM includes the [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-reference.html#serverless-sam-cli), which you can use to build, test, and deploy your application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ tocDepth: 2

You can deploy an application that uses Prisma ORM to the edge. Depending on which edge function provider and which database you use, there are different considerations and things to be aware of.

<details>
<summary>Questions answered in this page</summary>

- Which database drivers work on edge?
- How do driver adapters affect connections?
- When to use Prisma Postgres or Accelerate?

</details>

Here is a brief overview of all the edge function providers that are currently supported by Prisma ORM:

| Provider / Product | Supported natively with Prisma ORM | Supported with Prisma Postgres (and Prisma Accelerate)|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ tocDepth: 3

This page covers everything you need to know to deploy an app with Prisma ORM to a [Cloudflare Worker](https://developers.cloudflare.com/workers/) or to [Cloudflare Pages](https://developers.cloudflare.com/pages).

<details>
<summary>Questions answered in this page</summary>

- How to deploy Prisma to Cloudflare Workers?
- Which drivers work on Workers/Pages?
- How to configure DATABASE_URL and envs?

</details>

:::tip Use Prisma ORM without Rust binaries

If Prisma ORM's Rust engine binaries cause large bundle sizes, slow builds, or deployment issues (for example, in serverless or edge environments), you can use it without them using this configuration of your `generator` block:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ sidebar_class_name: preview-badge

This page covers everything you need to know to deploy an app that uses Prisma Client for talking to a database in [Vercel Edge Middleware](https://vercel.com/docs/functions/edge-middleware) or a [Vercel Function](https://vercel.com/docs/functions) deployed to the [Vercel Edge Runtime](https://vercel.com/docs/functions/runtimes/edge-runtime).

<details>
<summary>Questions answered in this page</summary>

- How to deploy Prisma on Vercel Edge?
- Which database drivers are supported?
- How to configure env and postinstall?

</details>

Vercel supports both Node.js and edge runtimes for Vercel Functions. The Node.js runtime is the default and recommended for most use cases.

:::note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ toc: true

Prisma ORM v6 introduces a number of **breaking changes** when you upgrade from an earlier Prisma ORM version. This guide explains how this upgrade might affect your application and gives instructions on how to handle any changes.

<details>
<summary>Questions answered in this page</summary>

- What changed in Prisma 6?
- How do I upgrade safely?
- Which breaking changes affect my app?

</details>

## Upgrade the `prisma` and `@prisma/client` packages to v6

To upgrade to Prisma ORM v6 from an earlier version, you need to update both the `prisma` and `@prisma/client` packages:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ slugSwitch: /orm/more/upgrade-guides/upgrade-from-prisma-1/upgrading-the-prisma-

This page explains the first step of your upgrade process: Taking your Prisma 1 configuration and upgrading it to Prisma ORM 2. Concretely, you will learn how to:

<details>
<summary>Questions answered in this page</summary>

- What are Prisma 1 → 2 schema incompatibilities?
- How to resolve Postgres-specific differences?
- How to use the upgrade CLI safely?

</details>

1. Add the Prisma ORM 2 CLI as a development dependency
1. Create your Prisma ORM 2 schema
1. Determine your connection URL and connect to your database
Expand Down
9 changes: 9 additions & 0 deletions content/800-guides/090-nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ community_section: true

## Introduction

<details>
<summary>Questions answered in this page</summary>

- How to set up Prisma with Next.js?
- How to deploy Next.js with Prisma to Vercel?
- How to handle migrations in production?

</details>

This guide shows you how to use Prisma with Next.js 15, a fullstack React framework. You'll learn how to create a [Prisma Postgres](/postgres/) instance, set up Prisma ORM with Next.js, handle migrations, and deploy your application to Vercel.

You can find a [deployment-ready example on GitHub](https://github.com/prisma/prisma-examples/blob/latest/orm/nextjs).
Expand Down
9 changes: 9 additions & 0 deletions content/800-guides/130-docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ tags:
community_section: true
---

<details>
<summary>Questions answered in this page</summary>

- How to run Prisma in Docker containers?
- How to configure Docker Compose with Prisma?
- How to handle migrations in Docker?

</details>

This guide walks you through setting up a Prisma ORM application within a Docker environment. You'll learn how to configure a Node.js project, integrate Prisma for database management, and orchestrate the application using Docker Compose. By the end, you'll have a fully functional Prisma application running in a Docker container.

## Prerequisites
Expand Down
9 changes: 9 additions & 0 deletions content/800-guides/220-astro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ community_section: true

## Introduction

<details>
<summary>Questions answered in this page</summary>

- How to integrate Prisma with Astro?
- How to set up Prisma Postgres in Astro?
- How to query data in Astro pages?

</details>

Prisma ORM offers type-safe database access, and [Astro](https://astro.build/) is built for performance. Together with [Prisma Postgres](https://www.prisma.io/postgres), you get a fast, content-first stack with zero cold starts and end-to-end speed.

In this guide, you'll learn to integrate Prisma ORM with a Prisma Postgres database in an Astro project from scratch. You can find a complete example of this guide on [GitHub](https://github.com/prisma/prisma-examples/tree/latest/orm/astro).
Expand Down
Loading