diff --git a/cSpell.json b/cSpell.json index 4fffb9697d..4bf3df6f3f 100644 --- a/cSpell.json +++ b/cSpell.json @@ -93,7 +93,8 @@ "Distroless", "Nikolas", "Supavisor", - "inshellisense" + "inshellisense", + "janedoe" ], "patterns": [ { diff --git a/content/200-orm/050-overview/300-prisma-in-your-stack/02-graphql.mdx b/content/200-orm/050-overview/300-prisma-in-your-stack/02-graphql.mdx index 8fb3f653cd..1d62c28c72 100644 --- a/content/200-orm/050-overview/300-prisma-in-your-stack/02-graphql.mdx +++ b/content/200-orm/050-overview/300-prisma-in-your-stack/02-graphql.mdx @@ -24,20 +24,20 @@ Note that a GraphQL schema can be written code-first or SDL-first. Check out thi The GraphQL schema and HTTP server are typically handled by separate libraries. Here is an overview of current GraphQL server tools and their purpose: | Library (npm package) | Purpose | Compatible with Prisma ORM | Prisma integration | -| :-------------------- | :-------------------------- | :--------------------- | :----------------------------------------------------------------------------- | -| `graphql` | GraphQL schema (code-first) | Yes | No | -| `graphql-tools` | GraphQL schema (SDL-first) | Yes | No | -| `type-graphql` | GraphQL schema (code-first) | Yes | [`typegraphql-prisma`](https://www.npmjs.com/package/typegraphql-prisma) | -| `nexus` | GraphQL schema (code-first) | Yes | [`nexus-prisma`](https://graphql-nexus.github.io/nexus-prisma) _Early Preview_ | -| `apollo-server` | HTTP server | Yes | n/a | -| `express-graphql` | HTTP server | Yes | n/a | -| `fastify-gql` | HTTP server | Yes | n/a | -| `graphql-yoga` | HTTP server | Yes | n/a | +| :-------------------- | :-------------------------- | :------------------------- | :----------------------------------------------------------------------------- | +| `graphql` | GraphQL schema (code-first) | Yes | No | +| `graphql-tools` | GraphQL schema (SDL-first) | Yes | No | +| `type-graphql` | GraphQL schema (code-first) | Yes | [`typegraphql-prisma`](https://www.npmjs.com/package/typegraphql-prisma) | +| `nexus` | GraphQL schema (code-first) | Yes | [`nexus-prisma`](https://graphql-nexus.github.io/nexus-prisma) _Early Preview_ | +| `apollo-server` | HTTP server | Yes | n/a | +| `express-graphql` | HTTP server | Yes | n/a | +| `fastify-gql` | HTTP server | Yes | n/a | +| `graphql-yoga` | HTTP server | Yes | n/a | In addition to these standalone and single-purpose libraries, there are several projects building integrated _application frameworks_: -| Framework | Stack | Built by | Prisma ORM | Description | -| :---------------------------------- | :-------- | :------------------------------------------------ | :--------------------- | :------------------------------------- | +| Framework | Stack | Built by | Prisma ORM | Description | +| :---------------------------------- | :-------- | :------------------------------------------------ | :------------------------- | :------------------------------------- | | [Redwood.js](https://redwoodjs.com) | Fullstack | [Tom Preston-Werner](https://github.com/mojombo/) | Built on top of Prisma ORM | _Bringing full-stack to the JAMstack._ | > **Note**: If you notice any GraphQL libraries/frameworks missing from the list, please let us know. diff --git a/content/200-orm/050-overview/500-databases/200-database-drivers.mdx b/content/200-orm/050-overview/500-databases/200-database-drivers.mdx index d6606f6695..d5df56e0fe 100644 --- a/content/200-orm/050-overview/500-databases/200-database-drivers.mdx +++ b/content/200-orm/050-overview/500-databases/200-database-drivers.mdx @@ -7,7 +7,7 @@ tocDepth: 4 ## Default built-in drivers -One of Prisma Client's components is the [Query Engine](/orm/more/under-the-hood/engines) . The Query Engine is responsible for transforming Prisma Client queries to SQL statements. The Query Engine connects to your database using the included drivers that don't require additional setup. The built-in drivers use TCP connections to connect to the database. +One of Prisma Client's components is the [Query Engine](/orm/more/under-the-hood/engines). The Query Engine is responsible for transforming Prisma Client queries to SQL statements. The Query Engine connects to your database via TCP using built-in drivers that don't require additional setup. ![Query flow from the user application to the database with Prisma Client](./images/drivers/qe-query-execution-flow.png) @@ -19,7 +19,7 @@ Prisma Client will use the Query Engine to transform the Prisma Client query to ![Query flow from the user application to the database using Prisma Client and driver adapters](./images/drivers/qe-query-engine-adapter.png) -There are 2 different types of driver adapters: +There are two different types of driver adapters: - [Database driver adapters](#database-driver-adapters) - [Serverless driver adapters](#serverless-driver-adapters) @@ -40,13 +40,13 @@ Prisma ORM maintains the following serverless driver adapters: - [Neon](/orm/overview/databases/neon#how-to-use-neons-serverless-driver-with-prisma-orm-preview) - [PlanetScale](/orm/overview/databases/planetscale#how-to-use-the-planetscale-serverless-driver-with-prisma-orm-preview) -## Community maintained database driver adapters +### Community-maintained database driver adapters You can also build your own driver adapter for the database you're using. The following is a list of community maintained driver adapters: - [TiDB](https://github.com/tidbcloud/prisma-adapter) -### How to use driver adapters +## How to use driver adapters To use this feature: @@ -71,6 +71,26 @@ To use this feature: - [PlanetScale](/orm/overview/databases/planetscale#how-to-use-the-planetscale-serverless-driver-with-prisma-orm-preview) - [Turso](/orm/overview/databases/turso#how-to-connect-and-query-a-turso-database) +## Notes about using driver adapters + +### Driver adapters don't read the connection string from the Prisma schema + +When using Prisma ORM's built-in drivers, the connection string is read from the `url` field of the `datasource` block in your Prisma schema. + +On the other hand, when using a driver adapter, the connection string needs to be provided in your _application code_ when the driver adapter is set up initially. Here is how this is done for the `pg` driver and the `@prisma/adapter-pg` adapter: + +```ts highlight=5,normal +import { PrismaClient } from '@prisma/client' +import { PrismaPg } from '@prisma/adapter-pg' +import { Pool } from 'pg' + +const pool = new Pool({ connectionString: env.DATABASE_URL }) +const adapter = new PrismaPg(pool) +const prisma = new PrismaClient({ adapter }) +``` + +See the docs for the driver adapter you're using for concrete setup instructions. + ### Driver adapters and custom output paths Since Prisma 5.9.0, when using the driver adapters Preview feature along with a [custom output path for Prisma Client](/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path), you cannot reference Prisma Client using a relative path. diff --git a/content/200-orm/050-overview/500-databases/600-mongodb.mdx b/content/200-orm/050-overview/500-databases/600-mongodb.mdx index 73cf2ab9bd..91f1d218a2 100644 --- a/content/200-orm/050-overview/500-databases/600-mongodb.mdx +++ b/content/200-orm/050-overview/500-databases/600-mongodb.mdx @@ -560,9 +560,9 @@ MongoDB types that are currently unsupported: When introspecting a MongoDB database, Prisma ORM uses the relevant [scalar types](/orm/prisma-schema/data-model/models#scalar-fields). Some special types also get additional native type annotations: -| MongoDB (Type \| Aliases) | Prisma ORM| Supported | Native database type attribute | Notes | -| ------------------------- | -------- | :-------: | :----------------------------- | :---- | -| `objectId` | `String` | ✔️ | `@db.ObjectId` | | +| MongoDB (Type \| Aliases) | Prisma ORM | Supported | Native database type attribute | Notes | +| ------------------------- | ---------- | :-------: | :----------------------------- | :---- | +| `objectId` | `String` | ✔️ | `@db.ObjectId` | | [Introspection](/orm/prisma-schema/introspection) adds native database types that are **not yet supported** as [`Unsupported`](/orm/reference/prisma-schema-reference#unsupported) fields: diff --git a/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx b/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx index f833d41a44..350a60021c 100644 --- a/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx +++ b/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx @@ -134,24 +134,24 @@ The following table lists differences between CockroachDB and PostgreSQL: The CockroachDB connector maps the [scalar types](/orm/prisma-schema/data-model/models#scalar-fields) from the Prisma ORM [data model](/orm/prisma-schema/data-model/models) to native column types. These native types are mostly the same as for PostgreSQL — see the [Native type mapping from Prisma ORM to CockroachDB](#native-type-mapping-from-prisma-orm-to-cockroachdb) for details. However, there are some limitations: | CockroachDB (Type \| Aliases) | Prisma ORM | Supported | Native database type attribute | Notes | -| ----------------------------- | --------- | :-------: | :----------------------------- | :------------------------------------------------------------------------------------------------------------------------- | -| `money` | `Decimal` | Not yet | `@db.Money` | Supported in PostgreSQL but [not currently in CockroachDB](https://github.com/cockroachdb/cockroach/issues/41578) | -| `xml` | `String` | Not yet | `@db.Xml` | Supported in PostgreSQL but [not currently in CockroachDB](https://github.com/cockroachdb/cockroach/issues/43355) | -| `jsonb` arrays | `Json[]` | Not yet | N/A | `Json[]` supported in PostgreSQL but [not currently in CockroachDB](https://github.com/cockroachdb/cockroach/issues/23468) | +| ----------------------------- | ---------- | :-------: | :----------------------------- | :------------------------------------------------------------------------------------------------------------------------- | +| `money` | `Decimal` | Not yet | `@db.Money` | Supported in PostgreSQL but [not currently in CockroachDB](https://github.com/cockroachdb/cockroach/issues/41578) | +| `xml` | `String` | Not yet | `@db.Xml` | Supported in PostgreSQL but [not currently in CockroachDB](https://github.com/cockroachdb/cockroach/issues/43355) | +| `jsonb` arrays | `Json[]` | Not yet | N/A | `Json[]` supported in PostgreSQL but [not currently in CockroachDB](https://github.com/cockroachdb/cockroach/issues/23468) | ## Other limitations The following table lists any other current known limitations of CockroachDB compared to PostgreSQL: -| Issue | Area | Notes | -| ------------------------------------------------------------------------------------------------ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Primary keys are named `primary` instead of `TABLE_pkey`, the Prisma ORM default. | Introspection | This means that they are introspected as `@id(map: "primary")`. This will be [fixed in CockroachDB 22.1](https://github.com/cockroachdb/cockroach/pull/70604). | -| Foreign keys are named `fk_COLUMN_ref_TABLE` instead of `TABLE_COLUMN_fkey`, the Prisma ORM default. | Introspection | This means that they are introspected as `@relation([...], map: "fk_COLUMN_ref_TABLE")`. This will be [fixed in CockroachDB 22.1](https://github.com/cockroachdb/cockroach/pull/70658) | -| Index types `Hash`, `Gist`, `SpGist` or `Brin` are not supported. | Schema | In PostgreSQL, Prisma ORM allows [configuration of indexes](/orm/prisma-schema/data-model/indexes#configuring-the-access-type-of-indexes-with-type-postgresql) to use the different index access method. CockroachDB only currently supports `BTree` and `Gin`. | -| Pushing to `Enum` types not supported | Client | Pushing to `Enum` types (e.g. `data: { enum { push: "A" }, }`) is currently [not supported in CockroachDB](https://github.com/cockroachdb/cockroach/issues/71388) | -| Searching on `String` fields without a full text index not supported | Client | Searching on `String` fields without a full text index (e.g. `where: { text: { search: "cat & dog", }, },`) is currently [not supported in CockroachDB](https://github.com/cockroachdb/cockroach/issues/7821) | -| Integer division not supported | Client | Integer division (e.g. `data: { int: { divide: 10, }, }`) is currently [not supported in CockroachDB](https://github.com/cockroachdb/cockroach/issues/41448) | -| Limited filtering on `Json` fields | Client | Currently CockroachDB [only supports](https://github.com/cockroachdb/cockroach/issues/49144) `equals` and `not` filtering on `Json` fields | +| Issue | Area | Notes | +| ---------------------------------------------------------------------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Primary keys are named `primary` instead of `TABLE_pkey`, the Prisma ORM default. | Introspection | This means that they are introspected as `@id(map: "primary")`. This will be [fixed in CockroachDB 22.1](https://github.com/cockroachdb/cockroach/pull/70604). | +| Foreign keys are named `fk_COLUMN_ref_TABLE` instead of `TABLE_COLUMN_fkey`, the Prisma ORM default. | Introspection | This means that they are introspected as `@relation([...], map: "fk_COLUMN_ref_TABLE")`. This will be [fixed in CockroachDB 22.1](https://github.com/cockroachdb/cockroach/pull/70658) | +| Index types `Hash`, `Gist`, `SpGist` or `Brin` are not supported. | Schema | In PostgreSQL, Prisma ORM allows [configuration of indexes](/orm/prisma-schema/data-model/indexes#configuring-the-access-type-of-indexes-with-type-postgresql) to use the different index access method. CockroachDB only currently supports `BTree` and `Gin`. | +| Pushing to `Enum` types not supported | Client | Pushing to `Enum` types (e.g. `data: { enum { push: "A" }, }`) is currently [not supported in CockroachDB](https://github.com/cockroachdb/cockroach/issues/71388) | +| Searching on `String` fields without a full text index not supported | Client | Searching on `String` fields without a full text index (e.g. `where: { text: { search: "cat & dog", }, },`) is currently [not supported in CockroachDB](https://github.com/cockroachdb/cockroach/issues/7821) | +| Integer division not supported | Client | Integer division (e.g. `data: { int: { divide: 10, }, }`) is currently [not supported in CockroachDB](https://github.com/cockroachdb/cockroach/issues/41448) | +| Limited filtering on `Json` fields | Client | Currently CockroachDB [only supports](https://github.com/cockroachdb/cockroach/issues/49144) `equals` and `not` filtering on `Json` fields | ## Type mapping between CockroachDB and the Prisma schema diff --git a/content/200-orm/100-prisma-schema/20-data-model/50-database-mapping.mdx b/content/200-orm/100-prisma-schema/20-data-model/50-database-mapping.mdx index 8284f97657..9c4f230645 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/50-database-mapping.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/50-database-mapping.mdx @@ -139,12 +139,12 @@ model Post { Since no explicit names are provided via `map` arguments Prisma will assume they follow our default naming convention. The following table lists the name of each constraint and index in the underlying database: -| Constraint or index | Follows convention | Underlying constraint or index names | +| Constraint or index | Follows convention | Underlying constraint or index names | | ---------------------------------- | ------------------ | ------------------------------------ | -| `@id` (on `User` > `id` field) | Yes | `User_pk` | -| `@@index` (on `Post`) | Yes | `Post_title_authorName_idx` | -| `@id` (on `Post` > `id` field) | Yes | `Post_pk` | -| `@relation` (on `Post` > `author`) | Yes | `Post_authorName_fkey` | +| `@id` (on `User` > `id` field) | Yes | `User_pk` | +| `@@index` (on `Post`) | Yes | `Post_title_authorName_idx` | +| `@id` (on `Post` > `id` field) | Yes | `Post_pk` | +| `@relation` (on `Post` > `author`) | Yes | `Post_authorName_fkey` | ### Using custom constraint / index names diff --git a/content/200-orm/200-prisma-client/100-queries/090-raw-database-access/index.mdx b/content/200-orm/200-prisma-client/100-queries/090-raw-database-access/index.mdx index cdcf6385b5..eaa0881cf3 100644 --- a/content/200-orm/200-prisma-client/100-queries/090-raw-database-access/index.mdx +++ b/content/200-orm/200-prisma-client/100-queries/090-raw-database-access/index.mdx @@ -4,7 +4,7 @@ metaTitle: 'Raw database access' metaDescription: 'Raw database access with Prisma Client.' --- -While Prisma ORM aims to make all your database queries intuitive, type-safe, and convenient, there may be situations where you need to drop down to raw queries. +While Prisma ORM aims to make all your database queries intuitive, type-safe, and convenient, there may be situations where you need to drop down to raw queries. This may happen for several reasons, e.g., because you need to optimize the performance of a specific query or because your data requirements can't be expressed by Prisma Client's query API. diff --git a/content/200-orm/200-prisma-client/200-special-fields-and-types/100-working-with-json-fields.mdx b/content/200-orm/200-prisma-client/200-special-fields-and-types/100-working-with-json-fields.mdx index f7f4be97c5..e615b2d492 100644 --- a/content/200-orm/200-prisma-client/200-special-fields-and-types/100-working-with-json-fields.mdx +++ b/content/200-orm/200-prisma-client/200-special-fields-and-types/100-working-with-json-fields.mdx @@ -548,14 +548,14 @@ const checkJson = await prisma.user.findMany({ ```json5 [{ status: 'expired', insuranceID: 92 }] - // PostgreSQL + // PostgreSQL ``` If you are using MySQL, you must pass in a single object to match: ```json5 { status: 'expired', insuranceID: 92 } - // MySQL + // MySQL ``` - If your filter array contains multiple objects, PostgreSQL will only return results if _all_ objects are present - not if at least one object is present. diff --git a/content/200-orm/200-prisma-client/500-deployment/301-edge/100-overview.mdx b/content/200-orm/200-prisma-client/500-deployment/301-edge/100-overview.mdx new file mode 100644 index 0000000000..6d152f79f9 --- /dev/null +++ b/content/200-orm/200-prisma-client/500-deployment/301-edge/100-overview.mdx @@ -0,0 +1,58 @@ +--- +title: 'Overview' +metaTitle: 'Overview (Deploy Prisma ORM at the Edge)' +metaDescription: 'Learn how to deploy your Prisma-backed apps to edge functions like Cloudflare Workers or Vercel Edge Functions' +tocDepth: 2 +--- + +## Deploying edge functions with Prisma ORM + +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. + +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 Accelerate | +| ---------------------- | ------------------------------------------------------- | -------------------------------- | +| Vercel Edge Functions | ✅ (Preview; only compatible drivers) | ✅ | +| Vercel Edge Middleware | ✅ (Preview; only compatible drivers) | ✅ | +| Cloudflare Workers | ✅ (Preview; only compatible drivers) | ✅ | +| Cloudflare Pages | ✅ (Preview; only compatible drivers) | ✅ | +| Deno Deploy | [Not yet](https://github.com/prisma/prisma/issues/2452) | ✅ | + +Deploying edge functions that use Prisma ORM on Cloudflare and Vercel is currently in [Preview](/orm/more/releases#preview). + +## Edge-compatibility of database drivers + +### Why are there limitations around database drivers in edge functions? + +Edge functions typically don't use the standard Node.js runtime. For example, Vercel Edge Functions and Cloudflare Workers are running code in [V8 isolates](https://v8docs.nodesource.com/node-0.8/d5/dda/classv8_1_1_isolate.html). Deno Deploy is using the [Deno](https://deno.com/) JavaScript runtime. As a consequence, these edge functions only have access to a small subset of the standard Node.js APIs and also have constrained computing resources (CPU and memory). + +In particular, the constraint of not being able to freely open TCP connections makes it difficult to talk to a traditional database from an edge function. While Cloudflare has introduced a [`connect()`](https://developers.cloudflare.com/workers/runtime-apis/tcp-sockets/) API that enables limited TCP connections, this still only enables database access using specific database drivers that are compatible with that API. + +> **Note**: [Prisma Accelerate](/accelerate) enables you to access _any_ database from _any_ edge function provider. No edge-compatible driver is necessary. + +### Which database drivers are edge-compatible? + +Here is an overview of the different database drivers and their compatibility with different edge function offerings: + +- [Neon Serverless](https://neon.tech/docs/serverless/serverless-driver) uses HTTP to access the database. It works with Cloudflare Workers and Vercel Edge Functions. +- [PlanetScale Serverless](https://planetscale.com/docs/tutorials/planetscale-serverless-driver) uses HTTP to access the database. It works with Cloudflare Workers and Vercel Edge Functions. +- [`node-postgres`](https://node-postgres.com/) (`pg`) uses Cloudflare's `connect()` (TCP) to access the database. It is only compatible with Cloudflare Workers, not with Vercel Edge Functions. +- [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) is used to access Turso databases. It works with Cloudflare Workers and Vercel Edge Functions. + +There's [also work being done](https://github.com/sidorares/node-mysql2/pull/2289) on the `node-mysql2` driver which will enable access to traditional MySQL databases from Cloudflare Workers and Pages in the future as well. + +You can use all of these drivers with Prisma ORM using the respective [driver adapters](/orm/overview/databases/database-drivers). + +Depending on which deployment provider and database/driver you use, there may be special considerations. Please take a look at the deployment docs for your respective scenario to make sure you can deploy your application successfully: + +- Cloudflare + - [PostgreSQL (traditional)](/orm/prisma-client/deployment/edge/deploy-to-cloudflare#postgresql-traditional) + - [PlanetScale](/orm/prisma-client/deployment/edge/deploy-to-cloudflare#planetscale) + - [Neon](/orm/prisma-client/deployment/edge/deploy-to-cloudflare#neon) +- Vercel + - [Vercel Postgres](/orm/prisma-client/deployment/edge/deploy-to-vercel#vercel-postgres) + - [Neon](/orm/prisma-client/deployment/edge/deploy-to-vercel#neon) + - [PlanetScale](/orm/prisma-client/deployment/edge/deploy-to-vercel#planetscale) + +If you want to deploy an app using Turso, you can follow the instructions [here](/orm/overview/databases/turso). diff --git a/content/200-orm/200-prisma-client/500-deployment/301-edge/450-deploy-to-cloudflare-workers.mdx b/content/200-orm/200-prisma-client/500-deployment/301-edge/450-deploy-to-cloudflare-workers.mdx deleted file mode 100644 index 4744b08b0e..0000000000 --- a/content/200-orm/200-prisma-client/500-deployment/301-edge/450-deploy-to-cloudflare-workers.mdx +++ /dev/null @@ -1,309 +0,0 @@ ---- -title: 'Deploy to Cloudflare Workers' -metaTitle: 'Deploy to Cloudflare Workers' -metaDescription: 'Learn how to deploy a TypeScript application to Cloudflare Workers that connects to PostgreSQL.' ---- - - - -Today you'll be deploying a Cloudflare Worker that uses Prisma ORM to save every request to a PostgreSQL database and fetches 20 of the most recent logs. - -This guide covers Prisma ORM, TypeScript, PostgreSQL, Prisma Accelerate, and Cloudflare Workers. - - - -## Prerequisites - -- A PostgreSQL database that is publicly accessible -- [Cloudflare Workers](https://workers.cloudflare.com/) account -- [Prisma Data Platform](https://console.prisma.io/) account -- Node.js & npm installed -- Git installed - -## 1. Set up your application - -Wrangler is the official Cloudflare Worker CLI. You will use it to develop and deploy to Cloudflare Workers. This guide uses [Wrangler v3](https://developers.cloudflare.com/workers/wrangler/). - -Open your terminal and navigate to a location of your choice. First, initialize your project using the [create-cloudflare-cli](https://www.npmjs.com/package/create-cloudflare). To do this, run the following command in your terminal: - -```terminal -npm create cloudflare@latest -``` - -This will ask you a few questions. - -```terminal -In which directory do you want to create your application? -``` - -Enter the name of your project, for example: `prisma-cloudflare-accelerate` - -```terminal -What type of application do you want to create? -``` - -Select the `"Hello World" Worker` option. - -```terminal -Would you like to use TypeScript? (y/n) -``` - -We also want to use TypeScript, so answer yes. - -```terminal -Would you like to use git to manage this Worker? (y/n) -``` - -We want to use Git, so answer yes. - -The command this will create a new project with a minimal preset configuration. Once `create-cloudflare-cli` is done, navigate to the project and open it on your editor of choice. - -Next, authenticate the Wrangler CLI with your Cloudflare Workers account. To do this, run the following command in your terminal: - -```terminal -npx wrangler login -``` - -You can now verify that you're logged in by running `npx wrangler whoami`. - -```terminal -npx wrangler whoami -``` - -## 2. Set up Prisma ORM - -Now you're ready to add Prisma ORM to the project. - -Install `prisma` as a development dependency: - -```terminal -npm install --save-dev prisma -``` - -Next, initialize Prisma ORM in your project with the following command: - -```terminal -npx prisma init -``` - -This creates a Prisma schema in `prisma/schema.prisma`. - - - -**Note:**

- -`prisma init` also creates an `.env` file. The `.env` file will contain a placeholder `DATABASE_URL` variable that will be used to update your database schema using Prisma Migrate. Update this value with your database's connection string. - -
- -Update your Prisma schema with the following data model: - -```prisma -generator client { - provider = "prisma-client-js" -} - -datasource db { - provider = "postgresql" - url = env("DATABASE_URL") -} - -model Log { - id Int @id @default(autoincrement()) - level Level - message String - meta Json -} - -enum Level { - Info - Warn - Error -} -``` - -The above data model will be used to persist and retrieve logs from your Cloudflare Worker - -## 3. Update your database schema - -To map your data model to the database schema, you need to use the `prisma migrate dev` CLI command: - -```terminal -npx prisma migrate dev --name init -``` - -The command does two things: - -1. It creates a new SQL migration file for this migration -1. It runs the SQL migration file against the database - -## 4. Enable Accelerate in the Prisma Data Platform - -Prisma ORM currently does not work on Cloudflare Workers yet. However, you can use Prisma ORM on Cloudflare Workers through [Prisma Accelerate](/accelerate). - -To get started with Prisma Accelerate: - -1. Sign up for a free [Prisma Data Platform account](https://console.prisma.io/) -1. Create a project -1. Navigate to the project you created -1. Enable Accelerate -1. Generate an Accelerate connection string and copy it to your clipboard - -## 5. Configure the Accelerate connection string in your project - -1. Rename the existing `DATABASE_URL` environment variable to `DIRECT_URL`. The `DIRECT_URL` variable will be used perform migrations and introspections. -1. Add the Prisma Accelerate connection string to your `.env` file. - - ```diff file=.env - -DATABASE_URL="postgres://..." - +DATABASE_URL="prisma://accelerate.prisma-data.net/?api_key=__API_KEY__" - +DIRECT_URL="postgres://..." - ``` - - Add [`directUrl`](/orm/reference/prisma-schema-reference#fields) property in `datasource` block in the `schema.prisma` file. - - ```prisma highlight=4;add file=prisma/schema.prisma - datasource db { - provider = "postgresql" - url = env("DATABASE_URL") - directUrl = env("DIRECT_URL") - } - ``` - - > The `directUrl` field is not required for Prisma Accelerate. It allows you to introspect and perform schema migrations. - -1. In `wrangler.toml` file, add a `[vars]` key and your connection string. - - ```diff file=wrangler.toml - name = "prisma-cloudflare-accelerate" - main = "src/main.ts" - compatibility_date = "2022-11-07" - - + [vars] - + DATABASE_URL = "prisma://accelerate.prisma-data.net/?api_key=__API_KEY__" - ``` - - - - Cloudflare Workers does not support `.env` files. To set environment variables, you can either adding the `[vars]` key in your `wrangler.toml` file or saving your environment variables in a `.dev.vars` file. Refer to [Cloudflare's documentation](https://developers.cloudflare.com/pages/platform/functions/bindings/#interact-with-your-environment-variables-locally) to learn more. - - - -1. Install the Prisma Accelerate extension - - ```bash - npm install @prisma/extension-accelerate - ``` - -You are now ready to generate a Prisma Client. - -## 6. Generate a Prisma Client - -Next, generate Prisma Client that connects to your database through [Prisma Accelerate](/accelerate) over HTTP. - -```terminal -npx prisma generate --no-engine -``` - - - -The `--no-engine` flag is available from Prisma ORM 5.2.0 and later. If you're using an earlier version of Prisma ORM, use the `--accelerate` flag. - -```terminal -npx prisma generate --accelerate -``` - - - -The generated Client has a smaller bundle size and is optimized for edge environments like Cloudflare Workers. - -The smaller bundle size is due to the fact that the interfaces talking to the database (the [Prisma ORM engines](/orm/more/under-the-hood/engines)) are no longer bundled with Prisma Client as this logic is now handled by Prisma Accelerate. - -## 7. Develop the Cloudflare Worker function - -You're now ready to create a Cloudflare Worker. Create a `src/index.ts` file with the following code: - -```ts -import { PrismaClient } from '@prisma/client/edge' -import { withAccelerate } from '@prisma/extension-accelerate' - -export interface Env { - DATABASE_URL: string -} - -export default { - async fetch( - request: Request, - env: Env, - ctx: ExecutionContext - ): Promise { - const prisma = new PrismaClient({ - datasourceUrl: env.DATABASE_URL, - }).$extends(withAccelerate()) - - await prisma.log.create({ - data: { - level: 'Info', - message: `${request.method} ${request.url}`, - meta: { - headers: JSON.stringify(request.headers), - }, - }, - }) - - const { data, info } = await prisma.log - .findMany({ - take: 20, - orderBy: { - id: 'desc', - }, - }) - .withAccelerateInfo() - - console.log(JSON.stringify(info)) - - return new Response(`request method: ${request.method}!`) - }, -} -``` - -> The [`info`](/accelerate/api-reference#return-type) object has additional information which can be useful for debugging. -> Accelerate can also be used to cache your query results. You can find more information on caching with Prisma Accelerate in [here](/accelerate). - -Run `npm run dev` to see your worker in development: - -``` -👂 Listening on http://127.0.0.1:8787 -``` - -Go ahead and open `http://127.0.0.1:8787`. If all goes well, you should see: - -``` -request method: GET! -``` - -Refresh the page a couple times to verify that it's working. - -## 8. Publish to Cloudflare Workers - -You're now ready to deploy to Cloudflare Workers. Run the following command: - -```terminal -npm run deploy -``` - -This will package and upload to Cloudflare. With a bit of luck, you'll see the following: - -``` -✨ Built successfully, built project size is 94 KiB. -✨ Successfully published your script to -https://prisma-cloudflare-accelerate.ankman.workers.dev -``` - -Visit your deployment URL and you'll again see: - -``` -request method: GET! -``` - -You're all set! You've successfully deployed a Cloudflare Worker written in TypeScript that uses Prisma ORM to talk to your PostgreSQL database. diff --git a/content/200-orm/200-prisma-client/500-deployment/301-edge/450-deploy-to-cloudflare.mdx b/content/200-orm/200-prisma-client/500-deployment/301-edge/450-deploy-to-cloudflare.mdx new file mode 100644 index 0000000000..92292611b3 --- /dev/null +++ b/content/200-orm/200-prisma-client/500-deployment/301-edge/450-deploy-to-cloudflare.mdx @@ -0,0 +1,541 @@ +--- +title: 'Deploy to Cloudflare Workers & Pages' +navTitle: Deploy to Cloudflare +metaTitle: 'Deploy to Cloudflare Workers & Pages' +metaDescription: 'Learn the things you need to know in order to deploy an app that uses Prisma Client for talking to a database to a Cloudflare Worker or to Cloudflare Pages.' +tocDepth: 3 +preview: true +--- + + + +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). + + + +## General considerations when deploying to Cloudflare Workers + +This section covers _general_ things you need to be aware of when deploying to Cloudflare Workers or Pages and are using Prisma ORM, regardless of the database provider you use. + +### Using an edge-compatible driver + +When deploying a Cloudflare Worker that uses Prisma ORM, you need to use an [edge-compatible driver](/orm/prisma-client/deployment/edge/overview#edge-compatibility-of-database-drivers) and its respective [driver adapter](/orm/overview/databases/database-drivers#driver-adapters) for Prisma ORM. + +The edge-compatible drivers for Cloudflare Workers and Pages are: + +- [Neon Serverless](https://neon.tech/docs/serverless/serverless-driver) uses HTTP to access the database +- [PlanetScale Serverless](https://planetscale.com/docs/tutorials/planetscale-serverless-driver) uses HTTP to access the database +- [`node-postgres`](https://node-postgres.com/) (`pg`) uses Cloudflare's `connect()` (TCP) to access the database +- [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) is used to access Turso databases + +There's [also work being done](https://github.com/sidorares/node-mysql2/pull/2289) on the `node-mysql2` driver which will enable access to traditional MySQL databases from Cloudflare Workers and Pages in the future as well. + +> **Note**: [Prisma Accelerate](/accelerate) enables you to access _any_ database from _any_ edge function provider. No edge-compatible driver is necessary. + +### Setting your database connection URL as an environment variable + +First, ensure that the `DATABASE_URL` is set as the `url` of the `datasource` in your Prisma schema: + +```prisma +datasource db { + provider = "postgresql" // this might also be `mysql` or another value depending on your database + url = env("DATABASE_URL") +} +``` + +#### Development + +When using your Worker in **development**, you can configure your database connection via the [`.dev.vars` file](https://developers.cloudflare.com/workers/configuration/secrets/#secrets-in-development) locally. + +Assuming you use the `DATABASE_URL` environment variable from above, you can set it inside `.dev.vars` as follows: + +```bash file=.dev.vars +DATABASE_URL="your-database-connection-string" +``` + +In the above snippet, `your-database-connection-string` is a placeholder that you need to replace with the value of your own connection string, for example: + +```bash file=.dev.vars +DATABASE_URL="postgresql://admin:mypassword42@somehost.aws.com:5432/mydb" +``` + +Note that the `.dev.vars` file is not compatible with `.env` files which are typically used by Prisma ORM. + +This means that you need to make sure that Prisma ORM gets access to the environment variable when needed, e.g. when running a Prisma CLI command like `prisma migrate dev`. + +There are several options for achieving this: + +- Run your Prisma CLI commands using [`dotenv`](https://www.npmjs.com/package/dotenv-cli) to specify from where the CLI should read the environment variable, for example: + ```terminal + dotenv -e .dev.vars -- npx prisma migrate dev + ``` +- Create a script in `package.json` that reads `.dev.vars` via [`dotenv`](https://www.npmjs.com/package/dotenv-cli). You can then execute `prisma` commands as follows: `npm run env -- npx prisma migrate dev`. Here's a reference for the script: + ```js file=package.json + "scripts": { "env": "dotenv -e .dev.vars" } + ``` +- Duplicate the `DATABASE_URL` and any other relevant env vars into a new file called `.env` which can then be used by Prisma ORM. + +> **Note**: If you're using an approach that requires `dotenv`, you need to have the [`dotenv-cli`](https://www.npmjs.com/package/dotenv-cli) package installed. You can do this e.g. by using this command: `npm install -g dotenv-cli`. + +#### Production + +When deploying your Worker to **production**, you'll need to set the database connection using the `wrangler` CLI: + +```terminal +npx wrangler secret put DATABASE_URL +``` + +The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal. + +> **Note**: This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not. + +### Size limits on free accounts + +Cloudflare has a [size limit of 1 MB for Workers on the free plan](https://developers.cloudflare.com/workers/platform/limits/). If your application bundle with Prisma ORM exceeds that size, we recommend upgrading to a paid Worker plan or using Prisma Accelerate to deploy your application. + +If you're running into this problem with `pg` and the `@prisma/adapter-pg` package, you can replace the `pg` with the custom [`@prisma/pg-worker`](https://github.com/prisma/prisma/tree/main/packages/pg-worker) package and use the [`@prisma/adapter-pg-worker`](https://github.com/prisma/prisma/tree/main/packages/adapter-pg-worker) adapter that belongs to it. + +`@prisma/pg-worker` is an optimized and lightweight version of `pg` that is designed to be used in a Worker. It is a drop-in replacement for `pg` and is fully compatible with Prisma ORM. + +### Deploying a Next.js app with `@cloudflare/next-on-pages` + +Cloudflare offers an option to run Next.js apps on Cloudflare Pages with [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages), see the [docs](https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site) for instructions. + +Based on some testing, we found the following: + +- You can deploy using the PlanetScale Serverless Driver. +- Neon currently doesn't work because of a probable bug in `@cloudflare/next-on-pages` (see [here](https://github.com/cloudflare/next-on-pages/issues/499#issuecomment-1863613990) and [here](https://github.com/cloudflare/workerd/issues/1513)). +- Traditional PostgreSQL deployments using `pg` don't work because `pg` itself currently does not work on `@cloudflare/next-on-pages` (see [here](https://github.com/cloudflare/next-on-pages/issues/605)). + +Feel free to reach out to us on [Discord](https://pris.ly/discord) if you find that anything has changed about this. + +### Set `PRISMA_CLIENT_FORCE_WASM=1` when running locally with `node` + +Some frameworks (e.g. [hono](https://hono.dev/)) use `node` instead of `wrangler` for running Workers locally. If you're using such a framework or are running your Worker locally with `node` for another reason, you need to set the `PRISMA_CLIENT_FORCE_WASM` environment variable: + +``` +export PRISMA_CLIENT_FORCE_WASM=1 +``` + +## Database-specific considerations & examples + +This section provides database-specific instructions for deploying a Cloudflare Worker with Prisma ORM. + +### Prerequisites + +As a prerequisite for the following section, you need to have a Cloudflare Worker running locally and the Prisma CLI installed. + +If you don't have that yet, you can run these commands: + +```terminal +npm create cloudflare@latest prisma-cloudflare-worker-example -- --type hello-world +cd prisma-cloudflare-worker-example +npm install prisma --save-dev +npx prisma init +``` + +We'll use the default `User` model for the example below: + +```prisma +model User { + id Int @id @default(autoincrement()) + email String @unique + name String? +} +``` + +### PostgreSQL (traditional) + +If you are using a traditional PostgreSQL database that's accessed via TCP and the `pg` driver, you need to: + +- use the `@prisma/adapter-pg` database adapter (via the `driverAdapters` Preview feature) +- set `node_compat = true` in `wrangler.toml` (see the [Cloudflare docs](https://developers.cloudflare.com/workers/wrangler/configuration/#add-polyfills-using-wrangler)) + +If you are running into a size issue and can't deploy your application because of that, you can use our slimmer variant of the `pg` driver package [`@prisma/pg-worker`](https://github.com/prisma/prisma/tree/main/packages/pg-worker) and the [`@prisma/adapter-pg-worker`](https://github.com/prisma/prisma/tree/main/packages/adapter-pg-worker) adapter that belongs to it. + +`@prisma/pg-worker` is an optimized and lightweight version of `pg` that is designed to be used in a Worker. It is a drop-in replacement for `pg` and is fully compatible with Prisma ORM. + +#### 1. Configure Prisma schema & database connection + +First, ensure that the database connection is configured properly. In your Prisma schema, set the `url` of the `datasource` block to the `DATABASE_URL` environment variable. You also need to enable the `driverAdapters` feature flag: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} +``` + +Next, you need to set the `DATABASE_URL` environment variable to the value of your database connection string. You'll do this in a file called `.dev.vars` used by Cloudflare: + +```bash file=.dev.vars +DATABASE_URL="postgresql://admin:mypassword42@somehost.aws.com:5432/mydb" +``` + +Because the Prisma CLI by default is only compatible with `.env` files, you can adjust your `package.json` with the following script that loads the env vars from `.dev.vars`. You can then use this script to load the env vars before executing a `prisma` command. + +Add this script to your `package.json`: + +```js file=package.json highlight=5;add +{ + // ... + "scripts": { + // .... + "env": "dotenv -e .dev.vars" + }, + // ... +} +``` + +Now you can execute Prisma CLI commands as follows while ensuring that the command has access to the env vars in `.dev.vars`: + +```terminal +npm run env -- npx prisma +``` + +#### 2. Install dependencies + +Next, install the required packages: + +```terminal +npm install @prisma/adapter-pg +npm install pg +npm install @types/pg --save-dev # if you're using TypeScript +``` + +#### 3. Set `node_compat = true` in `wrangler.toml` + +In your `wrangler.toml` file, add the following line: + +```toml file=wrangler.toml +node_compat = true +``` + +> **Note**: For Cloudflare Pages, using `node_compat` is not officially supported. If you want to use `pg` in Cloudflare Pages, you can find a workaround [here](https://github.com/cloudflare/workers-sdk/pull/2541#issuecomment-1954209855). + +#### 4. Migrate your database schema (if applicable) + +If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step): + +```terminal +npm run env -- npx prisma migrate dev --name init +``` + +#### 5. Use Prisma Client in your Worker to send a query to the database + +Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database: + +```ts +import { PrismaClient } from '@prisma/client' +import { PrismaPg } from '@prisma/adapter-pg' +import { Pool } from 'pg' + +export default { + async fetch(request, env, ctx) { + const pool = new Pool({ connectionString: env.DATABASE_URL }) + const adapter = new PrismaPg(pool) + const prisma = new PrismaClient({ adapter }) + + const users = await prisma.user.findMany() + const result = JSON.stringify(users) + return new Response(result) + }, +} +``` + +#### 6. Run the Worker locally + +To run the Worker locally, you can run the `wrangler dev` command: + +```terminal +npx wrangler dev +``` + +#### 7. Set the `DATABASE_URL` environment variable and deploy the Worker + +To deploy the Worker, you first need to the `DATABASE_URL` environment variable [via the `wrangler` CLI](https://developers.cloudflare.com/workers/configuration/secrets/#secrets-on-deployed-workers): + +```terminal +npx wrangler secret put DATABASE_URL +``` + +The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal. + +> **Note**: This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not. + +Then you can go ahead then deploy the Worker: + +```terminal +npx wrangler deploy +``` + +The command will output the URL where you can access the deployed Worker. + +### PlanetScale + +If you are using a PlanetScale database, you need to: + +- use the `@prisma/adapter-planetscale` database adapter (via the `driverAdapters` Preview feature) +- manually remove the conflicting `cache` field ([learn more]()): + + ```ts + export default { + async fetch(request, env, ctx) { + const client = new Client({ + url: env.DATABASE_URL, + // see https://github.com/cloudflare/workerd/issues/698 + fetch(url, init) { + delete init['cache'] + return fetch(url, init) + }, + }) + const adapter = new PrismaPlanetScale(client) + const prisma = new PrismaClient({ adapter }) + + // ... + }, + } + ``` + +#### 1. Configure Prisma schema & database connection + +First, ensure that the database connection is configured properly. In your Prisma schema, set the `url` of the `datasource` block to the `DATABASE_URL` environment variable. You also need to enable the `driverAdapters` feature flag: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} + +datasource db { + provider = "mysql" + url = env("DATABASE_URL") + relationMode = "prisma" // required for PlanetScale (as by default foreign keys are disabled) +} +``` + +Next, you need to set the `DATABASE_URL` environment variable to the value of your database connection string. You'll do this in a file called `.dev.vars` used by Cloudflare: + +```bash file=.dev.vars +DATABASE_URL="mysql://32qxa2r7hfl3102wrccj:password@us-east.connect.psdb.cloud/demo-cf-worker-ps?sslaccept=strict" +``` + +Because the Prisma CLI by default is only compatible with `.env` files, you can adjust your `package.json` with the following script that loads the env vars from `.dev.vars`. You can then use this script to load the env vars before executing a `prisma` command. + +Add this script to your `package.json`: + +```js file=package.json highlight=5;add +{ + // ... + "scripts": { + // .... + "env": "dotenv -e .dev.vars" + }, + // ... +} +``` + +Now you can execute Prisma CLI commands as follows while ensuring that the command has access to the env vars in `.dev.vars`: + +```terminal +npm run env -- npx prisma +``` + +#### 2. Install dependencies + +Next, install the required packages: + +```terminal +npm install @prisma/adapter-planetscale +npm install @planetscale/database +``` + +#### 3. Migrate your database schema (if applicable) + +If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step): + +```terminal +npm run env -- npx prisma db push +``` + +#### 4. Use Prisma Client in your Worker to send a query to the database + +Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database: + +```ts +import { PrismaClient } from '@prisma/client' +import { PrismaPlanetScale } from '@prisma/adapter-planetscale' +import { Client } from '@planetscale/database' + +export default { + async fetch(request, env, ctx) { + const client = new Client({ + url: env.DATABASE_URL, + // see https://github.com/cloudflare/workerd/issues/698 + fetch(url, init) { + delete init['cache'] + return fetch(url, init) + }, + }) + const adapter = new PrismaPlanetScale(client) + const prisma = new PrismaClient({ adapter }) + + const users = await prisma.user.findMany() + const result = JSON.stringify(users) + return new Response(result) + }, +} +``` + +#### 6. Run the Worker locally + +To run the Worker locally, you can run the `wrangler dev` command: + +```terminal +npx wrangler dev +``` + +#### 7. Set the `DATABASE_URL` environment variable and deploy the Worker + +To deploy the Worker, you first need to the `DATABASE_URL` environment variable [via the `wrangler` CLI](https://developers.cloudflare.com/workers/configuration/secrets/#secrets-on-deployed-workers): + +```terminal +npx wrangler secret put DATABASE_URL +``` + +The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal. + +> **Note**: This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not. + +Then you can go ahead then deploy the Worker: + +```terminal +npx wrangler deploy +``` + +The command will output the URL where you can access the deployed Worker. + +### Neon + +If you are using a Neon database, you need to: + +- use the `@prisma/adapter-neon` database adapter (via the `driverAdapters` Preview feature) + +#### 1. Configure Prisma schema & database connection + +First, ensure that the database connection is configured properly. In your Prisma schema, set the `url` of the `datasource` block to the `DATABASE_URL` environment variable. You also need to enable the `driverAdapters` feature flag: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} +``` + +Next, you need to set the `DATABASE_URL` environment variable to the value of your database connection string. You'll do this in a file called `.dev.vars` used by Cloudflare: + +```bash file=.dev.vars +DATABASE_URL="postgresql://janedoe:password@ep-nameless-pond-a23b1mdz.eu-central-1.aws.neon.tech/neondb?sslmode=require" +``` + +Because the Prisma CLI by default is only compatible with `.env` files, you can adjust your `package.json` with the following script that loads the env vars from `.dev.vars`. You can then use this script to load the env vars before executing a `prisma` command. + +Add this script to your `package.json`: + +```js file=package.json highlight=5;add +{ + // ... + "scripts": { + // .... + "env": "dotenv -e .dev.vars" + }, + // ... +} +``` + +Now you can execute Prisma CLI commands as follows while ensuring that the command has access to the env vars in `.dev.vars`: + +```terminal +npm run env -- npx prisma +``` + +#### 2. Install dependencies + +Next, install the required packages: + +```terminal +npm install @prisma/adapter-neon +npm install @neondatabase/serverless +``` + +#### 3. Migrate your database schema (if applicable) + +If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step): + +```terminal +npm run env -- npx prisma migrate dev --name init +``` + +#### 5. Use Prisma Client in your Worker to send a query to the database + +Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database: + +```ts +import { PrismaClient } from '@prisma/client' +import { PrismaNeon } from '@prisma/adapter-neon' +import { Pool } from '@neondatabase/serverless' + +export default { + async fetch(request, env, ctx) { + const neon = new Pool({ connectionString: env.DATABASE_URL }) + const adapter = new PrismaNeon(neon) + const prisma = new PrismaClient({ adapter }) + + const users = await prisma.user.findMany() + const result = JSON.stringify(users) + return new Response(result) + }, +} +``` + +#### 6. Run the Worker locally + +To run the Worker locally, you can run the `wrangler dev` command: + +```terminal +npx wrangler dev +``` + +#### 7. Set the `DATABASE_URL` environment variable and deploy the Worker + +To deploy the Worker, you first need to the `DATABASE_URL` environment variable [via the `wrangler` CLI](https://developers.cloudflare.com/workers/configuration/secrets/#secrets-on-deployed-workers): + +```terminal +npx wrangler secret put DATABASE_URL +``` + +The command is interactive and will ask you to enter the value for the `DATABASE_URL` env var as the next step in the terminal. + +> **Note**: This command requires you to be authenticated, and will ask you to log in to your Cloudflare account in case you are not. + +Then you can go ahead then deploy the Worker: + +```terminal +npx wrangler deploy +``` + +The command will output the URL where you can access the deployed Worker. + +### D1 + +[Coming soon](https://github.com/prisma/prisma/issues/13310). diff --git a/content/200-orm/200-prisma-client/500-deployment/301-edge/485-deploy-to-vercel.mdx b/content/200-orm/200-prisma-client/500-deployment/301-edge/485-deploy-to-vercel.mdx new file mode 100644 index 0000000000..7d18640c01 --- /dev/null +++ b/content/200-orm/200-prisma-client/500-deployment/301-edge/485-deploy-to-vercel.mdx @@ -0,0 +1,468 @@ +--- +title: 'Deploy to Vercel Edge Functions & Middleware' +navTitle: 'Deploy to Vercel' +metaTitle: 'Deploy to Vercel Edge Functions & Middleware' +metaDescription: 'Learn the things you need to know in order to deploy an Edge function that uses Prisma Client for talking to a database.' +tocDepth: 3 +preview: true +--- + + + +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). + +To deploy a Vercel Function to the Vercel Edge Runtime, you can set `export const runtime = 'edge'` outside the request handler of the Vercel Function. + + + +## General considerations when deploying to Vercel Edge Functions & Edge Middleware + +### Using an edge-compatible driver + +Vercel's Edge Runtime currently only supports a limited set of database drivers: + +- [Neon Serverless](https://neon.tech/docs/serverless/serverless-driver) uses HTTP to access the database (also compatible with [Vercel Postgres](https://vercel.com/docs/storage/vercel-postgres)) +- [PlanetScale Serverless](https://planetscale.com/docs/tutorials/planetscale-serverless-driver) uses HTTP to access the database +- [`@libsql/client`](https://github.com/tursodatabase/libsql-client-ts) is used to access Turso databases + +Note that [`node-postgres`](https://node-postgres.com/) (`pg`) is currently _not_ supported on Vercel Edge Functions. + +When deploying a Vercel Edge Function that uses Prisma ORM, you need to use one of these [edge-compatible drivers](/orm/prisma-client/deployment/edge/overview#edge-compatibility-of-database-drivers) and its respective [driver adapter](/orm/overview/databases/database-drivers#driver-adapters) for Prisma ORM. + +> **Note**: [Prisma Accelerate](/accelerate) enables you to access _any_ database from _any_ edge function provider. No edge-compatible driver is necessary. + +### Setting your database connection URL as an environment variable + +First, ensure that the `DATABASE_URL` is set as the `url` of the `datasource` in your Prisma schema: + +```prisma +datasource db { + provider = "postgresql" // this might also be `mysql` or another value depending on your database + url = env("DATABASE_URL") +} +``` + +#### Development + +When in **development**, you can configure your database connection via the `DATABASE_URL` environment variable (e.g. [using `.env` files](/orm/more/development-environment/environment-variables/env-files)). + +#### Production + +When deploying your Edge Function to **production**, you'll need to set the database connection using the `vercel` CLI: + +```terminal +npx vercel env add DATABASE_URL +``` + +This command is interactive and will ask you to select environments and provide the value for the `DATABASE_URL` in subsequent steps. + +Alternatively, you can configure the environment variable [via the UI](https://vercel.com/docs/projects/environment-variables#declare-an-environment-variable) of your project in the Vercel Dashboard. + +### Generate Prisma Client in `postinstall` hook + +In your `package.json`, you should add a `"postinstall"` section as follows: + +```js file=package.json +{ + // ..., + "postinstall: "prisma generate" +} +``` + +### Size limits on free accounts + +Vercel has a [size limit of 1 MB on free accounts](https://vercel.com/docs/functions/limitations). If your application bundle with Prisma ORM exceeds that size, we recommend upgrading to a paid account or using Prisma Accelerate to deploy your application. + +## Database-specific considerations & examples + +This section provides database-specific instructions for deploying a Vercel Edge Functions with Prisma ORM. + +### Prerequisites + +As a prerequisite for the following section, you need to have a Vercel Edge Function (which typically comes in the form of a Next.js API route) running locally and the Prisma and Vercel CLIs installed. + +If you don't have that yet, you can run these commands to set up a Next.js app from scratch (following the instructions of the [Vercel Edge Quickstart](https://vercel.com/docs/functions/edge-functions/quickstart)): + +```terminal +npm install -g vercel +npx create-next-app@latest +npm install prisma --save-dev +npx prisma init +``` + +We'll use the default `User` model for the example below: + +```prisma +model User { + id Int @id @default(autoincrement()) + email String @unique + name String? +} +``` + +### Vercel Postgres + +If you are using Vercel Postgres, you need to: + +- use the `@prisma/adapter-neon` database adapter (via the `driverAdapters` Preview feature) because Vercel Postgres uses [Neon](https://neon.tech/) under the hood +- be aware that Vercel by default calls the environment variable for the database connection string `POSTGRES_PRISMA_URL` while the default name used in the Prisma docs is typically `DATABASE_URL`; using Vercel's naming, you need to set the following fields on your `datasource` block: + ```prisma + datasource db { + provider = "postgresql" + url = env("POSTGRES_PRISMA_URL") // uses connection pooling + directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection + } + ``` + +#### 1. Configure Prisma schema & database connection + +First, ensure that the database connection is configured properly. In your Prisma schema, set the `url` of the `datasource` block to the `POSTGRES_PRISMA_URL` and the `directUrl` to the `POSTGRES_URL_NON_POOLING` environment variable. You also need to enable the `driverAdapters` feature flag: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} + +datasource db { + provider = "postgresql" + url = env("POSTGRES_PRISMA_URL") // uses connection pooling + directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection +} +``` + +Next, you need to set the `POSTGRES_PRISMA_URL` and `POSTGRES_URL_NON_POOLING` environment variable to the values of your database connection. + +If you ran `npx prisma init`, you can use the `.env` file that was created by this command to set these: + +```bash file=.env +POSTGRES_PRISMA_URL="postgres://user:password@host-pooler.region.postgres.vercel-storage.com:5432/name?pgbouncer=true&connect_timeout=15" +POSTGRES_URL_NON_POOLING="postgres://user:password@host.region.postgres.vercel-storage.com:5432/name" +``` + +#### 2. Install dependencies + +Next, install the required packages: + +```terminal +npm install @prisma/adapter-neon +npm install @neondatabase/serverless +``` + +#### 3. Configure `postinstall` hook + +Next, add a new key to the `scripts` section in your `package.json`: + +```js file=package.json highlight=5;add +{ + // ... + "scripts": { + // ... + "postinstall": "prisma generate" + } +} +``` + +#### 4. Migrate your database schema (if applicable) + +If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step): + +```terminal +npx prisma migrate dev --name init +``` + +#### 5. Use Prisma Client in your Vercel Edge Function to send a query to the database + +If you created the project from scratch, you can create a new edge function as follows. + +First, create a new API route, e.g. by using these commands: + +```terminal +mkdir src/app/api +mkdir src/app/api/edge +touch src/app/api/edge/route.ts +``` + +Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database in the new `app/api/edge/route.ts` file you just created: + +```ts file=app/api/edge/route.ts +import { NextResponse } from 'next/server' +import { PrismaClient } from '@prisma/client' +import { PrismaNeon } from '@prisma/adapter-neon' +import { Pool } from '@neondatabase/serverless' + +export const runtime = 'edge' + +export async function GET(request: Request) { + const neon = new Pool({ connectionString: process.env.POSTGRES_PRISMA_URL }) + const adapter = new PrismaNeon(neon) + const prisma = new PrismaClient({ adapter }) + + const users = await prisma.user.findMany() + + return NextResponse.json(users, { status: 200 }) +} +``` + +#### 6. Run the Edge Function locally + +Run the app with the following command: + +```terminal +npm run dev +``` + +You can now access the Edge Function via this URL: [`http://localhost:3000/api/edge`](http://localhost:3000/api/edge). + +#### 7. Set the `POSTGRES_PRISMA_URL` environment variable and deploy the Edge Function + +Run the following command to deploy your project with Vercel: + +```terminal +npx vercel deploy +``` + +Note that once the project was created on Vercel, you will need to set the `POSTGRES_PRISMA_URL` environment variable (and if this was your first deploy, it likely failed). You can do this either via the Vercel UI or by running the following command: + +``` +npx vercel env add POSTGRES_PRISMA_URL +``` + +At this point, you can get the URL of the deployed application from the Vercel Dashboard and access the edge function via the `/api/edge` route. + +### PlanetScale + +If you are using a PlanetScale database, you need to: + +- use the `@prisma/adapter-planetscale` database adapter (via the `driverAdapters` Preview feature) + +#### 1. Configure Prisma schema & database connection + +First, ensure that the database connection is configured properly. In your Prisma schema, set the `url` of the `datasource` block to the `DATABASE_URL` environment variable. You also need to enable the `driverAdapters` feature flag: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} + +datasource db { + provider = "mysql" + url = env("DATABASE_URL") + relationMode = "prisma" // required for PlanetScale (as by default foreign keys are disabled) +} +``` + +Next, you need to set the `DATABASE_URL` environment variable in your `.env` file that's used both by Prisma and Next.js to read your env vars: + +```bash file=.env +DATABASE_URL="mysql://32qxa2r7hfl3102wrccj:password@us-east.connect.psdb.cloud/demo-cf-worker-ps?sslaccept=strict" +``` + +#### 2. Install dependencies + +Next, install the required packages: + +```terminal +npm install @prisma/adapter-planetscale +npm install @planetscale/database +``` + +#### 3. Configure `postinstall` hook + +Next, add a new key to the `scripts` section in your `package.json`: + +```js file=package.json highlight=5;add +{ + // ... + "scripts": { + // ... + "postinstall": "prisma generate" + } +} +``` + +#### 4. Migrate your database schema (if applicable) + +If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step): + +```terminal +npx prisma db push +``` + +#### 5. Use Prisma Client in an Edge Function to send a query to the database + +If you created the project from scratch, you can create a new edge function as follows. + +First, create a new API route, e.g. by using these commands: + +```terminal +mkdir src/app/api +mkdir src/app/api/edge +touch src/app/api/edge/route.ts +``` + +Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database in the new `app/api/edge/route.ts` file you just created: + +```ts file=app/api/edge/route.ts +import { NextResponse } from 'next/server' +import { PrismaClient } from '@prisma/client' +import { PrismaPlanetScale } from '@prisma/adapter-planetscale' +import { Client } from '@planetscale/database' + +export const runtime = 'edge' + +export async function GET(request) { + const client = new Client({ url: process.env.DATABASE_URL }) + const adapter = new PrismaPlanetScale(client) + const prisma = new PrismaClient({ adapter }) + + const users = await prisma.user.findMany() + + return NextResponse.json(users, { status: 200 }) +} +``` + +#### 6. Run the Edge Function locally + +Run the app with the following command: + +```terminal +npm run dev +``` + +You can now access the Edge Function via this URL: [`http://localhost:3000/api/edge`](http://localhost:3000/api/edge). + +#### 7. Set the `DATABASE_URL` environment variable and deploy the Edge Function + +Run the following command to deploy your project with Vercel: + +```terminal +npx vercel deploy +``` + +Note that once the project was created on Vercel, you will need to set the `DATABASE_URL` environment variable (and if this was your first deploy, it likely failed). You can do this either via the Vercel UI or by running the following command: + +``` +npx vercel env add DATABASE_URL +``` + +At this point, you can get the URL of the deployed application from the Vercel Dashboard and access the edge function via the `/api/edge` route. + +### Neon + +If you are using a Neon database, you need to: + +- use the `@prisma/adapter-neon` database adapter (via the `driverAdapters` Preview feature) + +#### 1. Configure Prisma schema & database connection + +First, ensure that the database connection is configured properly. In your Prisma schema, set the `url` of the `datasource` block to the `DATABASE_URL` environment variable. You also need to enable the `driverAdapters` feature flag: + +```prisma file=schema.prisma +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} +``` + +Next, you need to set the `DATABASE_URL` environment variable in your `.env` file that's used both by Prisma and Next.js to read your env vars: + +```bash file=.env +DATABASE_URL="postgresql://janedoe:password@ep-nameless-pond-a23b1mdz.eu-central-1.aws.neon.tech/neondb?sslmode=require" +``` + +#### 2. Install dependencies + +Next, install the required packages: + +```terminal +npm install @prisma/adapter-neon +npm install @neondatabase/serverless +``` + +#### 3. Configure `postinstall` hook + +Next, add a new key to the `scripts` section in your `package.json`: + +```js file=package.json highlight=5;add +{ + // ... + "scripts": { + // ... + "postinstall": "prisma generate" + } +} +``` + +#### 4. Migrate your database schema (if applicable) + +If you ran `npx prisma init` above, you need to migrate your database schema to create the `User` table that's defined in your Prisma schema (if you already have all the tables you need in your database, you can skip this step): + +```terminal +npx prisma migrate dev --name init +``` + +#### 5. Use Prisma Client in an Edge Function to send a query to the database + +If you created the project from scratch, you can create a new edge function as follows. + +First, create a new API route, e.g. by using these commands: + +```terminal +mkdir src/app/api +mkdir src/app/api/edge +touch src/app/api/edge/route.ts +``` + +Here is a sample code snippet that you can use to instantiate `PrismaClient` and send a query to your database in the new `app/api/edge/route.ts` file you just created: + +```ts file=app/api/edge/route.ts +import { NextResponse } from 'next/server' +import { PrismaClient } from '@prisma/client' +import { PrismaNeon } from '@prisma/adapter-neon' +import { Pool } from '@neondatabase/serverless' + +export const runtime = 'edge' + +export async function GET(request) { + const neon = new Pool({ connectionString: process.env.DATABASE_URL }) + const adapter = new PrismaNeon(neon) + const prisma = new PrismaClient({ adapter }) + + const users = await prisma.user.findMany() + + return NextResponse.json(users, { status: 200 }) +} +``` + +#### 6. Run the Edge Function locally + +Run the app with the following command: + +```terminal +npm run dev +``` + +You can now access the Edge Function via this URL: [`http://localhost:3000/api/edge`](http://localhost:3000/api/edge). + +#### 7. Set the `DATABASE_URL` environment variable and deploy the Edge Function + +Run the following command to deploy your project with Vercel: + +```terminal +npx vercel deploy +``` + +Note that once the project was created on Vercel, you will need to set the `DATABASE_URL` environment variable (and if this was your first deploy, it likely failed). You can do this either via the Vercel UI or by running the following command: + +``` +npx vercel env add DATABASE_URL +``` + +At this point, you can get the URL of the deployed application from the Vercel Dashboard and access the edge function via the `/api/edge` route. diff --git a/content/200-orm/200-prisma-client/500-deployment/301-edge/index.mdx b/content/200-orm/200-prisma-client/500-deployment/301-edge/index.mdx index b918567f76..cb46530bec 100644 --- a/content/200-orm/200-prisma-client/500-deployment/301-edge/index.mdx +++ b/content/200-orm/200-prisma-client/500-deployment/301-edge/index.mdx @@ -7,10 +7,10 @@ tocDepth: 2 -If your application is deployed via an "Edge Function" offering or is deployed from a [serverless](/orm/prisma-client/deployment/serverless) offering and has a non-standard runtime, it is a edge deployed app. Common examples include [Cloudflare Workers](/orm/prisma-client/deployment/edge/deploy-to-cloudflare-workers), [Deno Deploy](/orm/prisma-client/deployment/edge/deploy-to-deno-deploy), and Vercel Edge Functions. +If your application is deployed via an "Edge Function" offering or is deployed from a [serverless](/orm/prisma-client/deployment/serverless) offering and has a non-standard runtime, it is a _edge-deployed_ app. Common examples for such offerings include [Cloudflare Workers or Pages](/orm/prisma-client/deployment/edge/deploy-to-cloudflare), [Vercel Edge Functions or Edge Middleware](/orm/prisma-client/deployment/edge/deploy-to-vercel), and [Deno Deploy](/orm/prisma-client/deployment/edge/deploy-to-deno-deploy). -## Guides for Edge Function providers +## In this section diff --git a/content/200-orm/200-prisma-client/500-deployment/210-module-bundlers.mdx b/content/200-orm/200-prisma-client/500-deployment/400-module-bundlers.mdx similarity index 71% rename from content/200-orm/200-prisma-client/500-deployment/210-module-bundlers.mdx rename to content/200-orm/200-prisma-client/500-deployment/400-module-bundlers.mdx index 0452fc3d45..509843fd10 100644 --- a/content/200-orm/200-prisma-client/500-deployment/210-module-bundlers.mdx +++ b/content/200-orm/200-prisma-client/500-deployment/400-module-bundlers.mdx @@ -12,8 +12,8 @@ Since Prisma Client is not only based on JavaScript code, but also relies on the To do so, you can use plugins that let you copy over static assets: -| Bundler | Plugin | -| :----------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------- | -| Webpack | [`copy-webpack-plugin`](https://github.com/webpack-contrib/copy-webpack-plugin#copy-webpack-plugin) | +| Bundler | Plugin | +| :---------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------- | +| Webpack | [`copy-webpack-plugin`](https://github.com/webpack-contrib/copy-webpack-plugin#copy-webpack-plugin) | | Webpack (with [Next.js monorepo](/orm/more/help-and-troubleshooting/help-articles/nextjs-prisma-client-monorepo)) | [`nextjs-monorepo-workaround-plugin`](https://www.npmjs.com/package/@prisma/nextjs-monorepo-workaround-plugin) | -| Parcel | [`parcel-plugin-static-files-copy`](https://github.com/elwin013/parcel-plugin-static-files-copy#readme) | +| Parcel | [`parcel-plugin-static-files-copy`](https://github.com/elwin013/parcel-plugin-static-files-copy#readme) | diff --git a/content/200-orm/500-reference/100-prisma-schema-reference.mdx b/content/200-orm/500-reference/100-prisma-schema-reference.mdx index 81facdeadb..1fdb4adfee 100644 --- a/content/200-orm/500-reference/100-prisma-schema-reference.mdx +++ b/content/200-orm/500-reference/100-prisma-schema-reference.mdx @@ -15,14 +15,14 @@ Defines a [data source](/orm/prisma-schema/overview/data-sources) in the Prisma A `datasource` block accepts the following fields: -| Name | Required | Type | Description | -| ------------------- | -------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `provider` | **Yes** | String (`postgresql`, `mysql`, `sqlite`, `sqlserver`, `mongodb`, `cockroachdb`) | Describes which data source connectors to use. | -| `url` | **Yes** | String (URL) | Connection URL including authentication info. Most connectors use [the syntax provided by the database](/orm/reference/connection-urls#format). | -| `shadowDatabaseUrl` | No | String (URL) | Connection URL to the shadow database used by Prisma Migrate. Allows you to use a cloud-hosted database as the shadow database. | +| Name | Required | Type | Description | +| ------------------- | -------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `provider` | **Yes** | String (`postgresql`, `mysql`, `sqlite`, `sqlserver`, `mongodb`, `cockroachdb`) | Describes which data source connectors to use. | +| `url` | **Yes** | String (URL) | Connection URL including authentication info. Most connectors use [the syntax provided by the database](/orm/reference/connection-urls#format). | +| `shadowDatabaseUrl` | No | String (URL) | Connection URL to the shadow database used by Prisma Migrate. Allows you to use a cloud-hosted database as the shadow database. | | `directUrl` | No | String (URL) | Connection URL for direct connection to the database.

If you use a connection pooler URL in the `url` argument (for example, if you use [Prisma Accelerate](/accelerate) or pgBouncer), Prisma CLI commands that require a direct connection to the database use the URL in the `directUrl` argument.

The `directUrl` property is supported by Prisma Studio from version 5.1.0 upwards. | -| `relationMode` | No | String (`foreignKeys`, `prisma`) | Sets whether [referential integrity](/orm/prisma-schema/data-model/relations/relation-mode) is enforced by foreign keys in the database or emulated in the Prisma Client.

In preview in versions 3.1.1 and later. The field is named `relationMode` in versions 4.5.0 and later, and was previously named `referentialIntegrity`. | -| `extensions` | No | List of strings (PostgreSQL extension names) | Allows you to [represent PostgreSQL extensions in your schema](/orm/prisma-schema/postgresql-extensions#how-to-represent-postgresql-extensions-in-your-prisma-schema). Available in preview for PostgreSQL only in Prisma ORM versions 4.5.0 and later. | +| `relationMode` | No | String (`foreignKeys`, `prisma`) | Sets whether [referential integrity](/orm/prisma-schema/data-model/relations/relation-mode) is enforced by foreign keys in the database or emulated in the Prisma Client.

In preview in versions 3.1.1 and later. The field is named `relationMode` in versions 4.5.0 and later, and was previously named `referentialIntegrity`. | +| `extensions` | No | List of strings (PostgreSQL extension names) | Allows you to [represent PostgreSQL extensions in your schema](/orm/prisma-schema/postgresql-extensions#how-to-represent-postgresql-extensions-in-your-prisma-schema). Available in preview for PostgreSQL only in Prisma ORM versions 4.5.0 and later. | The following providers are available: diff --git a/content/200-orm/500-reference/350-database-features.mdx b/content/200-orm/500-reference/350-database-features.mdx index f4bf4f5981..1b2b3a4d58 100644 --- a/content/200-orm/500-reference/350-database-features.mdx +++ b/content/200-orm/500-reference/350-database-features.mdx @@ -121,17 +121,17 @@ This section describes which database features exist on the NoSQL databases that The following table lists common MongoDB features and describes the level of support offered by Prisma ORM: | Feature | Supported by Prisma ORM | Notes | -| ----------------------------------------- | :-----------------: | :---------------------------------------------------------------------------------------------: | -| Embedded documents | ✔️ | | -| Transactions | ✔️ | | -| Indexes | ✔️ with caveats | Indexes can only be introspected if the field they refer to includes at least some data. | -| Autoincrementing IDs | No | | -| Compound IDs | No | MongoDB does not support composite IDs (`@@id`) | -| Generated `ObjectId` | ✔️ | See: [Defining IDs for MongoDB](/orm/prisma-schema/data-model/models#defining-ids-in-mongodb) | -| Arrays | ✔️ | | -| Enums | ✔️ | Implemented at Prisma ORM level | -| Native database types | ✔️ | See: [Field mapping reference](/orm/reference/prisma-schema-reference#model-field-scalar-types) | -| JSON support | ✔️ | Advanced `Json` field filtering is not yet supported. | -| DBrefs | No | -| Change streams | No | -| Direct access to the aggregation pipeline | No | +| ----------------------------------------- | :---------------------: | :---------------------------------------------------------------------------------------------: | +| Embedded documents | ✔️ | | +| Transactions | ✔️ | | +| Indexes | ✔️ with caveats | Indexes can only be introspected if the field they refer to includes at least some data. | +| Autoincrementing IDs | No | | +| Compound IDs | No | MongoDB does not support composite IDs (`@@id`) | +| Generated `ObjectId` | ✔️ | See: [Defining IDs for MongoDB](/orm/prisma-schema/data-model/models#defining-ids-in-mongodb) | +| Arrays | ✔️ | | +| Enums | ✔️ | Implemented at Prisma ORM level | +| Native database types | ✔️ | See: [Field mapping reference](/orm/reference/prisma-schema-reference#model-field-scalar-types) | +| JSON support | ✔️ | Advanced `Json` field filtering is not yet supported. | +| DBrefs | No | +| Change streams | No | +| Direct access to the aggregation pipeline | No | diff --git a/content/200-orm/500-reference/500-preview-features/050-client-preview-features.mdx b/content/200-orm/500-reference/500-preview-features/050-client-preview-features.mdx index 07053bff87..56e36beb10 100644 --- a/content/200-orm/500-reference/500-preview-features/050-client-preview-features.mdx +++ b/content/200-orm/500-reference/500-preview-features/050-client-preview-features.mdx @@ -57,36 +57,36 @@ To enable a Prisma Client Preview feature: In the list below, you can find a history of Prisma Client and Prisma schema features that were in Preview and are now in general availability. The features are sorted by the most recent version in which they were promoted to general availability. -| Feature | Released into Preview | Released into General Availability | -| -------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------: | -| `jsonProtocol` | [4.11.0](https://github.com/prisma/prisma/releases/tag/4.11.0) | [5.0.0](https://github.com/prisma/prisma/releases/tag/5.0.0) | -| [`extendedWhereUnique`](/orm/reference/prisma-client-reference#filter-on-non-unique-fields-with-userwhereuniqueinput) | [4.5.0](https://github.com/prisma/prisma/releases/tag/4.5.0) | [5.0.0](https://github.com/prisma/prisma/releases/tag/5.0.0) | -| [`fieldReference`](/orm/reference/prisma-client-reference#compare-columns-in-the-same-table) | [4.3.0](https://github.com/prisma/prisma/releases/tag/4.3.0) | [5.0.0](https://github.com/prisma/prisma/releases/tag/5.0.0) | -| [`clientExtensions`](/orm/prisma-client/client-extensions) | [4.7.0](https://github.com/prisma/prisma/releases/tag/4.7.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) | -| [`filteredRelationCount`](/orm/prisma-client/queries/aggregation-grouping-summarizing#filter-the-relation-count) | [4.3.0](https://github.com/prisma/prisma/releases/tag/4.3.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) | -| [`orderByNulls`](/orm/prisma-client/queries/filtering-and-sorting#sort-with-null-records-first-or-last) | [4.1.0](https://github.com/prisma/prisma/releases/tag/4.1.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) | -| [`referentialIntegrity`](/orm/prisma-schema/data-model/relations/relation-mode) | [3.1.1](https://github.com/prisma/prisma/releases/tag/3.1.1) | [4.7.0](https://github.com/prisma/prisma/releases/tag/4.7.0) | -| [`interactiveTransactions`](/orm/prisma-client/queries/transactions#interactive-transactions) | [2.29.0](https://github.com/prisma/prisma/releases/tag/2.29.0) |
  • [4.7.0](https://github.com/prisma/prisma/releases/tag/4.7.0)
  • with Prisma Accelerate [5.1.1](https://github.com/prisma/prisma/releases/tag/5.1.1)
| -| [`extendedIndexes`](/orm/prisma-schema/data-model/indexes) | [3.5.0](https://github.com/prisma/prisma/releases/tag/3.5.0) | [4.0.0](https://github.com/prisma/prisma/releases/tag/4.0.0) | -| [`filterJson`](/orm/prisma-client/special-fields-and-types/working-with-json-fields#filter-on-a-json-field) | [2.23.0](https://github.com/prisma/prisma/releases/tag/2.23.0) | [4.0.0](https://github.com/prisma/prisma/releases/tag/4.0.0) | -| [`improvedQueryRaw`](/orm/prisma-client/queries/raw-database-access/raw-queries#raw-query-type-mapping) | [3.14.0](https://github.com/prisma/prisma/releases/tag/3.14.0) | [4.0.0](https://github.com/prisma/prisma/releases/tag/4.0.0) | -| [`cockroachdb`](/orm/overview/databases/cockroachdb) |
  • [3.9.0](https://github.com/prisma/prisma/releases/tag/3.9.0)
  • migrations in CockroachDB in [3.11.0](https://github.com/prisma/prisma/releases/tag/3.11.0)
| [3.14.0](https://github.com/prisma/prisma/releases/tag/3.14.0) | -| [`mongodb`](/orm/overview/databases/mongodb) |
  • [2.27.0](https://github.com/prisma/prisma/releases/tag/2.27.0)
  • introspection of MongoDB in [3.2.0](https://github.com/prisma/prisma/releases/tag/3.2.0)
  • introspection of embedded documents in [3.4.0](https://github.com/prisma/prisma/releases/tag/3.4.0)
  • MongoDB embedded documents in [3.10.0](https://github.com/prisma/prisma/releases/tag/3.10.0)
  • introspection of embedded documents in [3.10.0](https://github.com/prisma/prisma/releases/tag/3.10.0)
  • raw query support for MongoDB in [3.9.0](https://github.com/prisma/prisma/releases/tag/3.9.0)
  • filters in embedded documents as an Experimental Feature in [3.11.0](https://github.com/prisma/prisma/releases/tag/3.11.0)
  • order by embedded documents in [3.11.0](https://github.com/prisma/prisma/releases/tag/3.11.0)
| [3.12.0](https://github.com/prisma/prisma/releases/tag/3.12.0) | -| [`microsoftSqlServer`](/orm/overview/databases/sql-server) | [2.10.0](https://github.com/prisma/prisma/releases/tag/2.10.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | -| [`namedConstraints`](/orm/prisma-schema/data-model/database-mapping#constraint-and-index-names) | [2.29.0](https://github.com/prisma/prisma/releases/tag/2.29.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | -| [`referentialActions`](/orm/prisma-schema/data-model/relations/referential-actions) | [2.26.0](https://github.com/prisma/prisma/releases/tag/2.26.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | -| [`orderByAggregateGroup`](/orm/prisma-client/queries/aggregation-grouping-summarizing#order-by-aggregate-group) | [2.21.0](https://github.com/prisma/prisma/releases/tag/2.21.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | -| [`orderByRelation`](/orm/prisma-client/queries/filtering-and-sorting#sort-by-relation) |
  • [2.16.0](https://github.com/prisma/prisma/releases/tag/2.16.0)
  • order by aggregates of relations in [2.19.0](https://github.com/prisma/prisma/releases/tag/2.19.0)
| [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | -| [`selectRelationCount`](/orm/prisma-client/queries/aggregation-grouping-summarizing#count-relations) | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | -| `napi` | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | -| [`groupBy`](/orm/reference/prisma-client-reference#groupby) | [2.14.0](https://github.com/prisma/prisma/releases/tag/2.14.0) | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | -| [`createMany`](/orm/reference/prisma-client-reference#createmany) | [2.16.0](https://github.com/prisma/prisma/releases/tag/2.16.0) | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | -| [`nativeTypes`](/orm/prisma-schema/data-model/models#native-types-mapping) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | [2.17.0](https://github.com/prisma/prisma/releases/tag/2.17.0) | -| [`uncheckedScalarInputs`](/orm/prisma-client/queries/relation-queries#create-a-single-record-and-multiple-related-records) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | [2.15.0](https://github.com/prisma/prisma/releases/tag/2.15.0) | -| [`transactionApi`](/orm/prisma-client/queries/transactions#the-transaction-api) | [2.1.0](https://github.com/prisma/prisma/releases/tag/2.1.0) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | -| [`connectOrCreate`](/orm/reference/prisma-client-reference#connectorcreate) | [2.1.0](https://github.com/prisma/prisma/releases/tag/2.1.0) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | -| [`atomicNumberOperations`](/orm/reference/prisma-client-reference#atomic-number-operations) | [2.6.0](https://github.com/prisma/prisma/releases/tag/2.6.0) | [2.10.0](https://github.com/prisma/prisma/releases/tag/2.10.0) | -| [`insensitiveFilters` (PostgreSQL)](/orm/prisma-client/queries/filtering-and-sorting#case-insensitive-filtering) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | [2.8.0](https://github.com/prisma/prisma/releases/tag/2.8.0) | -| [`middlewares`](/orm/prisma-client/client-extensions/middleware) | [2.3.0](https://github.com/prisma/prisma/releases/tag/2.3.0) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | -| [`aggregateApi`](/orm/prisma-client/queries/aggregation-grouping-summarizing#aggregate) | [2.2.0](https://github.com/prisma/prisma/releases/tag/2.2.0) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | -| [`distinct`](/orm/reference/prisma-client-reference#distinct) | [2.3.0](https://github.com/prisma/prisma/releases/tag/2.3.0) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | +| Feature | Released into Preview | Released into General Availability | +| -------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | +| `jsonProtocol` | [4.11.0](https://github.com/prisma/prisma/releases/tag/4.11.0) | [5.0.0](https://github.com/prisma/prisma/releases/tag/5.0.0) | +| [`extendedWhereUnique`](/orm/reference/prisma-client-reference#filter-on-non-unique-fields-with-userwhereuniqueinput) | [4.5.0](https://github.com/prisma/prisma/releases/tag/4.5.0) | [5.0.0](https://github.com/prisma/prisma/releases/tag/5.0.0) | +| [`fieldReference`](/orm/reference/prisma-client-reference#compare-columns-in-the-same-table) | [4.3.0](https://github.com/prisma/prisma/releases/tag/4.3.0) | [5.0.0](https://github.com/prisma/prisma/releases/tag/5.0.0) | +| [`clientExtensions`](/orm/prisma-client/client-extensions) | [4.7.0](https://github.com/prisma/prisma/releases/tag/4.7.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) | +| [`filteredRelationCount`](/orm/prisma-client/queries/aggregation-grouping-summarizing#filter-the-relation-count) | [4.3.0](https://github.com/prisma/prisma/releases/tag/4.3.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) | +| [`orderByNulls`](/orm/prisma-client/queries/filtering-and-sorting#sort-with-null-records-first-or-last) | [4.1.0](https://github.com/prisma/prisma/releases/tag/4.1.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) | +| [`referentialIntegrity`](/orm/prisma-schema/data-model/relations/relation-mode) | [3.1.1](https://github.com/prisma/prisma/releases/tag/3.1.1) | [4.7.0](https://github.com/prisma/prisma/releases/tag/4.7.0) | +| [`interactiveTransactions`](/orm/prisma-client/queries/transactions#interactive-transactions) | [2.29.0](https://github.com/prisma/prisma/releases/tag/2.29.0) |
  • [4.7.0](https://github.com/prisma/prisma/releases/tag/4.7.0)
  • with Prisma Accelerate [5.1.1](https://github.com/prisma/prisma/releases/tag/5.1.1)
| +| [`extendedIndexes`](/orm/prisma-schema/data-model/indexes) | [3.5.0](https://github.com/prisma/prisma/releases/tag/3.5.0) | [4.0.0](https://github.com/prisma/prisma/releases/tag/4.0.0) | +| [`filterJson`](/orm/prisma-client/special-fields-and-types/working-with-json-fields#filter-on-a-json-field) | [2.23.0](https://github.com/prisma/prisma/releases/tag/2.23.0) | [4.0.0](https://github.com/prisma/prisma/releases/tag/4.0.0) | +| [`improvedQueryRaw`](/orm/prisma-client/queries/raw-database-access/raw-queries#raw-query-type-mapping) | [3.14.0](https://github.com/prisma/prisma/releases/tag/3.14.0) | [4.0.0](https://github.com/prisma/prisma/releases/tag/4.0.0) | +| [`cockroachdb`](/orm/overview/databases/cockroachdb) |
  • [3.9.0](https://github.com/prisma/prisma/releases/tag/3.9.0)
  • migrations in CockroachDB in [3.11.0](https://github.com/prisma/prisma/releases/tag/3.11.0)
| [3.14.0](https://github.com/prisma/prisma/releases/tag/3.14.0) | +| [`mongodb`](/orm/overview/databases/mongodb) |
  • [2.27.0](https://github.com/prisma/prisma/releases/tag/2.27.0)
  • introspection of MongoDB in [3.2.0](https://github.com/prisma/prisma/releases/tag/3.2.0)
  • introspection of embedded documents in [3.4.0](https://github.com/prisma/prisma/releases/tag/3.4.0)
  • MongoDB embedded documents in [3.10.0](https://github.com/prisma/prisma/releases/tag/3.10.0)
  • introspection of embedded documents in [3.10.0](https://github.com/prisma/prisma/releases/tag/3.10.0)
  • raw query support for MongoDB in [3.9.0](https://github.com/prisma/prisma/releases/tag/3.9.0)
  • filters in embedded documents as an Experimental Feature in [3.11.0](https://github.com/prisma/prisma/releases/tag/3.11.0)
  • order by embedded documents in [3.11.0](https://github.com/prisma/prisma/releases/tag/3.11.0)
| [3.12.0](https://github.com/prisma/prisma/releases/tag/3.12.0) | +| [`microsoftSqlServer`](/orm/overview/databases/sql-server) | [2.10.0](https://github.com/prisma/prisma/releases/tag/2.10.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | +| [`namedConstraints`](/orm/prisma-schema/data-model/database-mapping#constraint-and-index-names) | [2.29.0](https://github.com/prisma/prisma/releases/tag/2.29.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | +| [`referentialActions`](/orm/prisma-schema/data-model/relations/referential-actions) | [2.26.0](https://github.com/prisma/prisma/releases/tag/2.26.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | +| [`orderByAggregateGroup`](/orm/prisma-client/queries/aggregation-grouping-summarizing#order-by-aggregate-group) | [2.21.0](https://github.com/prisma/prisma/releases/tag/2.21.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | +| [`orderByRelation`](/orm/prisma-client/queries/filtering-and-sorting#sort-by-relation) |
  • [2.16.0](https://github.com/prisma/prisma/releases/tag/2.16.0)
  • order by aggregates of relations in [2.19.0](https://github.com/prisma/prisma/releases/tag/2.19.0)
| [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | +| [`selectRelationCount`](/orm/prisma-client/queries/aggregation-grouping-summarizing#count-relations) | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | +| `napi` | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | [3.0.1](https://github.com/prisma/prisma/releases/tag/3.0.1) | +| [`groupBy`](/orm/reference/prisma-client-reference#groupby) | [2.14.0](https://github.com/prisma/prisma/releases/tag/2.14.0) | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | +| [`createMany`](/orm/reference/prisma-client-reference#createmany) | [2.16.0](https://github.com/prisma/prisma/releases/tag/2.16.0) | [2.20.0](https://github.com/prisma/prisma/releases/tag/2.20.0) | +| [`nativeTypes`](/orm/prisma-schema/data-model/models#native-types-mapping) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | [2.17.0](https://github.com/prisma/prisma/releases/tag/2.17.0) | +| [`uncheckedScalarInputs`](/orm/prisma-client/queries/relation-queries#create-a-single-record-and-multiple-related-records) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | [2.15.0](https://github.com/prisma/prisma/releases/tag/2.15.0) | +| [`transactionApi`](/orm/prisma-client/queries/transactions#the-transaction-api) | [2.1.0](https://github.com/prisma/prisma/releases/tag/2.1.0) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | +| [`connectOrCreate`](/orm/reference/prisma-client-reference#connectorcreate) | [2.1.0](https://github.com/prisma/prisma/releases/tag/2.1.0) | [2.11.0](https://github.com/prisma/prisma/releases/tag/2.11.0) | +| [`atomicNumberOperations`](/orm/reference/prisma-client-reference#atomic-number-operations) | [2.6.0](https://github.com/prisma/prisma/releases/tag/2.6.0) | [2.10.0](https://github.com/prisma/prisma/releases/tag/2.10.0) | +| [`insensitiveFilters` (PostgreSQL)](/orm/prisma-client/queries/filtering-and-sorting#case-insensitive-filtering) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | [2.8.0](https://github.com/prisma/prisma/releases/tag/2.8.0) | +| [`middlewares`](/orm/prisma-client/client-extensions/middleware) | [2.3.0](https://github.com/prisma/prisma/releases/tag/2.3.0) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | +| [`aggregateApi`](/orm/prisma-client/queries/aggregation-grouping-summarizing#aggregate) | [2.2.0](https://github.com/prisma/prisma/releases/tag/2.2.0) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | +| [`distinct`](/orm/reference/prisma-client-reference#distinct) | [2.3.0](https://github.com/prisma/prisma/releases/tag/2.3.0) | [2.5.0](https://github.com/prisma/prisma/releases/tag/2.5.0) | diff --git a/content/200-orm/800-more/450-migrating-to-prisma/01-migrate-from-typeorm.mdx b/content/200-orm/800-more/450-migrating-to-prisma/01-migrate-from-typeorm.mdx index a3af1af588..3a6932db71 100644 --- a/content/200-orm/800-more/450-migrating-to-prisma/01-migrate-from-typeorm.mdx +++ b/content/200-orm/800-more/450-migrating-to-prisma/01-migrate-from-typeorm.mdx @@ -1114,7 +1114,7 @@ This would also result in a more ergonomic and less verbose Prisma Client API to If your database provider requires tables to have primary keys then you have to use explicit syntax, and manually create the join model with a primary key. - This is because relation tables (JOIN tables) created by Prisma ORM (expressed via - `@relation`) for many-to-many relations using implicit syntax do not have + This is because relation tables (JOIN tables) created by Prisma ORM (expressed + via `@relation`) for many-to-many relations using implicit syntax do not have primary keys. diff --git a/content/300-accelerate/200-getting-started.mdx b/content/300-accelerate/200-getting-started.mdx index d7071ce236..e4825be050 100644 --- a/content/300-accelerate/200-getting-started.mdx +++ b/content/300-accelerate/200-getting-started.mdx @@ -119,6 +119,7 @@ npx prisma generate --accelerate ``` If your Prisma version is below `5.0.0`, generate Prisma Client with the `--data-proxy` option: + ### 2.4. Extend your Prisma Client instance to add the Accelerate extension diff --git a/content/600-about/200-prisma-docs/30-docs-components/01-mdx-examples.mdx b/content/600-about/200-prisma-docs/30-docs-components/01-mdx-examples.mdx index 718cfbf292..e789fb0277 100644 --- a/content/600-about/200-prisma-docs/30-docs-components/01-mdx-examples.mdx +++ b/content/600-about/200-prisma-docs/30-docs-components/01-mdx-examples.mdx @@ -455,7 +455,7 @@ yarn prisma init $ yarn prisma init yarn run v1.22.0 warning package.json: No license field -$ /Users/nikolasburk/Desktop/tsdf/node_modules/.bin/prisma init +$ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init ✔ Your Prisma schema was created at prisma/schema.prisma. You can now open it in your favorite editor. @@ -493,7 +493,7 @@ yarn prisma init $ yarn prisma init yarn run v1.22.0 warning package.json: No license field -$ /Users/nikolasburk/Desktop/tsdf/node_modules/.bin/prisma init +$ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init ✔ Your Prisma schema was created at prisma/schema.prisma. You can now open it in your favorite editor. @@ -531,7 +531,7 @@ yarn prisma init $ yarn prisma init yarn run v1.22.0 warning package.json: No license field -$ /Users/nikolasburk/Desktop/tsdf/node_modules/.bin/prisma init +$ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init ✔ Your Prisma schema was created at prisma/schema.prisma. You can now open it in your favorite editor. @@ -569,7 +569,7 @@ yarn prisma init $ yarn prisma init yarn run v1.22.0 warning package.json: No license field -$ /Users/nikolasburk/Desktop/tsdf/node_modules/.bin/prisma init +$ /Users/janedoe/Desktop/tsdf/node_modules/.bin/prisma init ✔ Your Prisma schema was created at prisma/schema.prisma. You can now open it in your favorite editor. diff --git a/src/components/footer.tsx b/src/components/footer.tsx index 9327992cca..a23f25a44a 100644 --- a/src/components/footer.tsx +++ b/src/components/footer.tsx @@ -414,7 +414,6 @@ const FooterSec = ({ > Enterprise - diff --git a/src/pages/index.tsx b/src/pages/index.tsx index d80715695c..de5cd4cfe4 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -668,9 +668,9 @@ const Homepage = () => {

Databases

- Prisma ORM works seamlessly across most popular databases and service providers.
Refer - to our Database features matrix for information about supported features and types for - each database. + Prisma ORM works seamlessly across most popular databases and service providers.
{' '} + Refer to our Database features matrix for information about supported features and types + for each database. {DatabaseData.map((e: any) => ( diff --git a/vercel.json b/vercel.json index 1e04771513..bebbe5c5ec 100644 --- a/vercel.json +++ b/vercel.json @@ -475,502 +475,402 @@ "source": "/docs/guides/prisma-guides/prisma-migrate-guides", "destination": "/docs/guides/prisma-guides/add-prisma-migrate-to-a-project" }, - { "source": "/docs/guides/prisma-guides/prisma-migrate-guides/add-prisma-migrate-to-a-project", "destination": "/docs/guides/prisma-guides/add-prisma-migrate-to-a-project" }, - { "source": "/docs/concepts/components/prisma-client/distinct", "destination": "/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#select-distinct" }, - { "source": "/docs/concepts/components/prisma-client/configuring-the-prisma-client-api", "destination": "/docs/concepts/components/prisma-client/generating-prisma-client/customizing-the-prisma-client-api" }, - { "source": "/docs/concepts/components/prisma-client/constructor", "destination": "/docs/reference/api-reference/prisma-client-reference#prismaclient" }, - { "source": "/docs/concepts/components/prisma-client/field-selection", "destination": "/docs/concepts/components/prisma-client/select-fields" }, - { "source": "/docs/concepts/components/prisma-client/error-reference", "destination": "/docs/reference/api-reference/error-reference" }, - { "source": "/docs/concepts/components/prisma-client/sorting", "destination": "/docs/concepts/components/prisma-client/filtering-and-sorting" }, - { "source": "/docs/concepts/components/prisma-client/filtering", "destination": "/docs/concepts/components/prisma-client/filtering-and-sorting" }, - { "source": "/docs/concepts/components/prisma-client/aggregations", "destination": "/docs/concepts/components/prisma-client/aggregation-grouping-summarizing" }, - { "source": "/docs/concepts/components/prisma-client/working-with-json", "destination": "/docs/concepts/components/prisma-client/working-with-advanced-types" }, - { "source": "/docs/concepts/components/prisma-client/group-by", "destination": "/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#group-by-preview" }, - { "source": "/docs/concepts/components/prisma-client/advanced-usage-of-generated-types", "destination": "/docs/concepts/components/prisma-client/working-with-generated-types" }, - { "source": "/docs/concepts/components/preview-features/native-types/native-types-mappings", "destination": "/docs/reference/api-reference/prisma-schema-reference#model-field-scalar-types" }, - { "source": "/docs/concepts/components/preview-features/native-types", "destination": "/docs/concepts/components/prisma-schema/data-model#native-types-mapping" }, - { "source": "/docs/concepts/components/prisma-client/generating-prisma-client", "destination": "/docs/concepts/components/prisma-client/working-with-prismaclient/generating-prisma-client" }, - { "source": "/docs/concepts/components/prisma-client/generating-prisma-client/customizing-the-prisma-client-api", "destination": "/docs/concepts/components/prisma-client/working-with-prismaclient/use-custom-model-and-field-names" }, - { "source": "/docs/concepts/components/prisma-client/connection-management", "destination": "/docs/concepts/components/prisma-client/working-with-prismaclient/connection-management" }, - { "source": "/docs/concepts/components/prisma-client/logging", "destination": "/docs/concepts/components/prisma-client/working-with-prismaclient/logging" }, - { "source": "/docs/concepts/components/prisma-client/error-formatting", "destination": "/docs/concepts/components/prisma-client/working-with-prismaclient/error-formatting" }, - { "source": "/docs/concepts/components/prisma-client/deployment", "destination": "/docs/guides/deployment/deployment" }, - { "source": "/docs/concepts/components/prisma-migrate/prisma-migrate-flows", "destination": "/docs/concepts/components/prisma-migrate" }, - { "source": "/docs/guides/prisma-guides/seed-database", "destination": "/docs/guides/application-lifecycle/seed-database" }, - { "source": "/docs/guides/prisma-guides/add-prisma-migrate-to-a-project", "destination": "/docs/guides/database/developing-with-prisma-migrate/add-prisma-migrate-to-a-project" }, - { "source": "/docs/about/creating-bug-reports", "destination": "/docs/support/creating-bug-reports" }, - { "source": "/docs/concepts/components/prisma-client/working-with-generated-types", "destination": "/docs/concepts/components/prisma-client/advanced-type-safety/operating-against-partial-structures-of-model-types" }, - { "source": "/docs/reference/utility-types-reference", "destination": "/docs/reference/api-reference/prisma-client-reference#prismavalidator" }, - { "source": "/docs/concepts/components/prisma-client/query-engine", "destination": "/docs/concepts/components/prisma-engines/query-engine" }, - { "source": "/docs/concepts/overview/under-the-hood", "destination": "/docs/concepts/components/prisma-engines" }, - { "source": "/docs/guides/application-lifecycle/add-prisma-migrate-to-a-project", "destination": "/docs/guides/database/developing-with-prisma-migrate/add-prisma-migrate-to-a-project" }, - { "source": "/docs/guides/deployment/patching-production", "destination": "/docs/guides/database/patching-production" }, - { "source": "/docs/guides/deployment/production-troubleshooting", "destination": "/docs/guides/database/production-troubleshooting" }, - { "source": "/docs/guides/application-lifecycle/:any*", "destination": "/docs/guides/database/:any*" }, - { "source": "/docs/guides/deployment/deploying-to-azure-functions", "destination": "/docs/guides/deployment/deployment-guides/deploying-to-azure-functions" }, - { "source": "/docs/guides/deployment/deploying-to-heroku", "destination": "/docs/guides/deployment/deployment-guides/deploying-to-heroku" }, - { "source": "/docs/guides/deployment/deploying-to-vercel", "destination": "/docs/guides/deployment/deployment-guides/deploying-to-vercel" }, - { "source": "/docs/guides/deployment/deploying-to-aws-lambda", "destination": "/docs/guides/deployment/deployment-guides/deploying-to-aws-lambda" }, - { "source": "/docs/guides/deployment/deploying-to-netlify", "destination": "/docs/guides/deployment/deployment-guides/deploying-to-netlify" }, - { "source": "/docs/guides/general-guides/database-workflows/cascading-deletes/:any*", "destination": "/docs/concepts/components/prisma-schema/relations/referential-actions" }, - { "source": "/docs/guides/database/advanced-database-tasks/cascading-deletes/:any*", "destination": "/docs/concepts/components/prisma-schema/relations/referential-actions" }, - { "source": "/docs/guides/general-guides/database-workflows/data-validation/:any*", "destination": "/docs/guides/database/advanced-database-tasks/data-validation/:any*" }, - { "source": "/docs/guides/general-guides/database-workflows/sql-views", "destination": "https://github.com/prisma/prisma/issues/678" }, - { "source": "/docs/guides/general-guides/database-workflows/sql-views-postgres", "destination": "https://github.com/prisma/prisma/issues/678" }, - { "source": "/docs/guides/database/advanced-database-tasks/sql-views-postgres", "destination": "https://github.com/prisma/prisma/issues/678" }, - { "source": "/docs/guides/general-guides/database-workflows/sql-views-mysql", "destination": "https://github.com/prisma/prisma/issues/678" }, - { "source": "/docs/guides/database/advanced-database-tasks/sql-views-mysql", "destination": "https://github.com/prisma/prisma/issues/678" }, - { "source": "/docs/guides/general-guides/database-workflows/unique-constraints-and-indexes", "destination": "/docs/concepts/components/prisma-schema/data-model#defining-a-unique-field" }, - { "source": "/docs/guides/general-guides/database-workflows/unique-constraints-and-indexes/mysql", "destination": "/docs/concepts/components/prisma-schema/data-model#defining-a-unique-field" }, - { "source": "/docs/guides/database/advanced-database-tasks/unique-constraints-and-indexes/postgresql", "destination": "/docs/concepts/components/prisma-schema/data-model#defining-a-unique-field" }, - { "source": "/docs/guides/general-guides/database-workflows/unique-constraints-and-indexes/sqlite", "destination": "/docs/concepts/components/prisma-schema/data-model#defining-a-unique-field" }, - { "source": "/docs/guides/general-guides/database-workflows/foreign-keys", "destination": "/docs/concepts/components/prisma-schema/relations#relational-databases" }, - { "source": "/docs/guides/general-guides/database-workflows/foreign-keys/mysql", "destination": "/docs/concepts/components/prisma-schema/relations#relational-databases" }, - { "source": "/docs/guides/general-guides/database-workflows/foreign-keys/postgresql", "destination": "/docs/concepts/components/prisma-schema/relations#relational-databases" }, - { "source": "/docs/guides/general-guides/database-workflows/foreign-keys/sqlite", "destination": "/docs/concepts/components/prisma-schema/relations#relational-databases" }, - { "source": "/docs/guides/prisma-guides/:any*", "destination": "/docs/guides/performance-and-optimization/:any*" }, - { "source": "/docs/mongodb", "destination": "/docs/concepts/database-connectors/mongodb" }, - { "source": "/docs/guides/database/developing-with-prisma-migrate/advanced-migrate-scenarios", "destination": "/docs/guides/database/developing-with-prisma-migrate/customizing-migrations" }, - { "source": "/docs/concepts/components/prisma-migrate/type-mapping", "destination": "/docs/concepts/components/prisma-migrate/supported-types-and-db-features" }, - { "source": "/docs/concepts/components/prisma-client/working-with-advanced-types", "destination": "/docs/concepts/components/prisma-client/working-with-fields" }, - { "source": "/docs/concepts/more/codemod", "destination": "/docs/guides/upgrade-guides/upgrading-versions/codemods" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/connect-your-database-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/connect-your-database-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/using-prisma-migrate-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/using-prisma-migrate-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/install-prisma-client-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/install-prisma-client-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/querying-the-database-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/querying-the-database-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/next-steps-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/next-steps-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/connect-your-database-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/connect-your-database-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/introspection-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/introspection-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/install-prisma-client-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/install-prisma-client-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/querying-the-database-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/querying-the-database-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/next-steps-typescript-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/next-steps-typescript-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/connect-your-database-node-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/connect-your-database-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/using-prisma-migrate-node-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/using-prisma-migrate-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/install-prisma-client-node-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/install-prisma-client-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/querying-the-database-node-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/querying-the-database-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/next-steps-node-postgres", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/next-steps-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/connect-your-database-node-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/connect-your-database-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/introspection-node-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/introspection-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/install-prisma-client-node-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/install-prisma-client-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/querying-the-database-node-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/querying-the-database-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/next-steps-node-postgres", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/next-steps-node-postgresql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/connect-your-database-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/connect-your-database-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/using-prisma-migrate-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/using-prisma-migrate-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/install-prisma-client-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/install-prisma-client-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/querying-the-database-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/querying-the-database-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/next-steps-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/next-steps-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/connect-your-database-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/connect-your-database-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/introspection-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/introspection-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/install-prisma-client-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/install-prisma-client-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/querying-the-database-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/querying-the-database-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/next-steps-typescript-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/next-steps-typescript-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/connect-your-database-node-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/connect-your-database-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/using-prisma-migrate-node-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/using-prisma-migrate-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/install-prisma-client-node-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/install-prisma-client-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/querying-the-database-node-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/querying-the-database-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/start-from-scratch/next-steps-node-mysql", "destination": "/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/next-steps-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/connect-your-database-node-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/connect-your-database-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/introspection-node-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/introspection-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/install-prisma-client-node-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/install-prisma-client-node-mysql" }, - { "source": "/docs/getting-started/setup-prisma/add-to-existing-project/querying-the-database-node-mysql", "destination": "/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/querying-the-database-node-mysql" @@ -3879,6 +3779,14 @@ "source": "/docs/platform/platform-console", "destination": "/docs/platform" }, + { + "source": "/docs/orm/prisma-client/deployment/edge/deploy-to-cloudflare-workers", + "destination": "/docs/orm/prisma-client/deployment/edge/deploy-to-cloudflare" + }, + { + "source": "/docs/orm/prisma-client/deployment/module-bundlers", + "destination": "/docs/orm/prisma-client/deployment/module-bundlers" + }, { "source": "/docs/pulse/current-limitations", "destination": "/docs/pulse/known-limitations",