From 4e0ea97285dbb53fd189676571a911d11d5d21c2 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sat, 15 Nov 2025 01:51:03 +0530 Subject: [PATCH 1/2] update --- .../100-introduction/100-what-is-prisma.mdx | 39 ++++++-- .../100-introduction/300-data-modeling.mdx | 4 +- .../300-prisma-in-your-stack/01-rest.mdx | 3 +- .../300-prisma-in-your-stack/03-fullstack.mdx | 3 +- .../04-is-prisma-an-orm.mdx | 12 ++- .../500-databases/200-database-drivers.mdx | 8 +- .../500-databases/300-postgresql.mdx | 24 ++++- .../050-overview/500-databases/400-mysql.mdx | 22 ++++- .../050-overview/500-databases/500-sqlite.mdx | 8 +- .../500-databases/800-sql-server/index.mdx | 24 ++++- .../500-databases/840-cockroachdb.mdx | 22 ++++- .../500-databases/850-planetscale.mdx | 7 +- .../500-databases/880-supabase.mdx | 3 - .../050-overview/500-databases/890-neon.mdx | 5 +- .../050-overview/500-databases/900-turso.mdx | 2 +- .../050-overview/600-beyond-prisma-orm.mdx | 2 +- .../100-prisma-schema/10-overview/index.mdx | 5 +- .../20-data-model/10-models.mdx | 6 +- .../410-referential-actions/index.mdx | 4 +- .../20-relations/420-relation-mode.mdx | 2 - .../20-data-model/30-indexes.mdx | 3 +- .../20-data-model/40-views.mdx | 1 + .../20-data-model/60-multi-schema.mdx | 2 +- .../65-externally-managed-tables.mdx | 3 +- .../70-unsupported-database-features.mdx | 5 +- .../20-data-model/80-table-inheritance.mdx | 6 +- .../005-introduction.mdx | 5 +- .../010-generating-prisma-client.mdx | 11 ++- .../015-instantiate-prisma-client.mdx | 4 +- .../100-connection-management.mdx | 2 +- .../115-connection-pool.mdx | 6 +- .../050-databases-connections/index.mdx | 9 +- .../200-read-replicas.mdx | 2 +- .../300-no-rust-engine.mdx | 44 ++++----- .../100-queries/030-crud.mdx | 6 +- .../100-queries/037-relation-queries.mdx | 3 +- .../100-queries/050-filtering-and-sorting.mdx | 3 +- .../100-queries/058-transactions.mdx | 6 +- .../100-queries/060-full-text-search.mdx | 6 +- .../100-queries/061-custom-validation.mdx | 6 +- .../100-queries/062-computed-fields.mdx | 6 +- .../100-queries/064-custom-models.mdx | 6 +- .../150-using-raw-sql/300-safeql.mdx | 4 +- .../080-null-and-undefined.mdx | 3 +- .../100-working-with-json-fields.mdx | 3 +- .../830-prisma-type-system.mdx | 1 - .../201-serverless/300-deploy-to-vercel.mdx | 2 +- .../400-deploy-to-aws-lambda.mdx | 2 +- .../301-edge/450-deploy-to-cloudflare.mdx | 71 +++++++++++--- .../301-edge/485-deploy-to-vercel.mdx | 95 ++++++++++++++----- .../301-edge/550-deploy-to-deno-deploy.mdx | 5 +- .../240-metrics.mdx | 7 +- .../250-opentelemetry-tracing.mdx | 9 +- ...245-troubleshooting-binary-size-issues.mdx | 3 +- .../050-getting-started.mdx | 1 - .../200-shadow-database.mdx | 2 - .../300-workflows/10-seeding.mdx | 6 +- .../110-native-database-types.mdx | 1 - .../120-native-database-functions.mdx | 4 +- .../20-prototyping-your-schema.mdx | 8 +- .../050-prisma-client-reference.mdx | 31 +++--- .../100-prisma-schema-reference.mdx | 9 +- .../200-prisma-cli-reference.mdx | 40 ++++---- .../500-reference/380-connection-urls.mdx | 1 - .../050-client-preview-features.mdx | 3 +- .../100-under-the-hood/100-engines.mdx | 5 +- .../500-upgrading-to-prisma-6.mdx | 25 ++--- .../001-rejectonnotfound-changes.mdx | 2 +- .../101-jsonprotocol-changes.mdx | 6 +- .../600-upgrading-to-prisma-5/index.mdx | 10 +- .../150-referential-actions.mdx | 4 +- .../800-upgrading-to-prisma-3/index.mdx | 6 +- .../03-upgrading-the-prisma-layer-mysql.mdx | 6 +- ...-upgrading-the-prisma-layer-postgresql.mdx | 6 +- .../04-upgrading-nexus-prisma-to-nexus.mdx | 4 +- .../05-upgrading-prisma-binding-to-nexus.mdx | 2 +- ...-upgrading-prisma-binding-to-sdl-first.mdx | 2 +- .../07-upgrading-a-rest-api.mdx | 2 +- .../08-upgrade-from-mongodb-beta.mdx | 4 +- .../800-more/350-ai-tools/100-cursor.mdx | 6 +- .../800-more/350-ai-tools/200-tabnine.mdx | 10 +- .../800-more/350-ai-tools/300-windsurf.mdx | 6 +- .../350-ai-tools/400-github-copilot.mdx | 2 +- ...ompletion-in-graphql-resolvers-with-js.mdx | 6 +- .../300-implicit-to-explicit-conversion.mdx | 2 +- .../400-nextjs-help.mdx | 4 +- ...-comparing-columns-through-raw-queries.mdx | 12 +-- .../800-check-constraints.mdx | 14 +-- .../900-prisma-nuxt-module.mdx | 15 +-- ...50-typescript-performance-optimization.mdx | 4 +- package-lock.json | 36 ++++++- 91 files changed, 545 insertions(+), 317 deletions(-) diff --git a/content/200-orm/050-overview/100-introduction/100-what-is-prisma.mdx b/content/200-orm/050-overview/100-introduction/100-what-is-prisma.mdx index ea7fd22348..8c49f33730 100644 --- a/content/200-orm/050-overview/100-introduction/100-what-is-prisma.mdx +++ b/content/200-orm/050-overview/100-introduction/100-what-is-prisma.mdx @@ -41,11 +41,11 @@ Every project that uses a tool from the Prisma ORM toolkit starts with a [Prisma ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model Post { @@ -101,10 +101,35 @@ model User { In this schema, you configure three things: -- **Data source**: Specifies your database connection (via an environment variable) +- **Data source**: Specifies your database connection. Database connection URLs are configured in `prisma.config.ts`. - **Generator**: Indicates that you want to generate Prisma Client - **Data model**: Defines your application models +### Configuring database connections + +Database connection URLs are configured in a `prisma.config.ts` file. Create a `prisma.config.ts` file in your project root: + +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + migrations: { + path: 'prisma/migrations', + seed: 'tsx ./prisma/seed.ts', + }, + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + + + +**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell. + + + ### The Prisma schema data model On this page, the focus is on the data model. You can learn more about [Data sources](/orm/prisma-schema/overview/data-sources) and [Generators](/orm/prisma-schema/overview/generators) on the respective docs pages. @@ -142,9 +167,9 @@ Then, you can run `prisma generate`: npx prisma generate ``` -The `prisma generate` command reads your Prisma schema and _generates_ Prisma Client code. The code is [generated into the `node_modules/.prisma/client` folder by default](/orm/prisma-client/setup-and-configuration/generating-prisma-client#the-prismaclient-npm-package). +The `prisma generate` command reads your Prisma schema and _generates_ Prisma Client code. The code is generated into the path specified in the `output` field of your generator block (e.g., `./generated` as shown in the schema example above). -After you change your data model, you'll need to manually re-generate Prisma Client by running `prisma generate` to ensure the code inside `node_modules/.prisma/client` gets updated. +After you change your data model, you'll need to manually re-generate Prisma Client by running `prisma generate` to ensure the generated code gets updated. #### Using Prisma Client to send queries to your database @@ -156,7 +181,7 @@ Once Prisma Client has been generated, you can import it in your code and send q ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/client' const prisma = new PrismaClient() ``` @@ -165,7 +190,7 @@ const prisma = new PrismaClient() ```js -const { PrismaClient } = require('@prisma/client') +const { PrismaClient } = require('./generated/client') const prisma = new PrismaClient() ``` diff --git a/content/200-orm/050-overview/100-introduction/300-data-modeling.mdx b/content/200-orm/050-overview/100-introduction/300-data-modeling.mdx index af5cd1a998..107ddf045b 100644 --- a/content/200-orm/050-overview/100-introduction/300-data-modeling.mdx +++ b/content/200-orm/050-overview/100-introduction/300-data-modeling.mdx @@ -211,9 +211,9 @@ export type User = { In addition to the generated types, Prisma Client also provides a data access API that you can use once you've installed the `@prisma/client` package: ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' // or -// const { PrismaClient } = require('@prisma/client') +// const { PrismaClient } = require('../prisma/generated/client') const prisma = new PrismaClient() diff --git a/content/200-orm/050-overview/300-prisma-in-your-stack/01-rest.mdx b/content/200-orm/050-overview/300-prisma-in-your-stack/01-rest.mdx index 5b7c5e3442..0b3c249fb0 100644 --- a/content/200-orm/050-overview/300-prisma-in-your-stack/01-rest.mdx +++ b/content/200-orm/050-overview/300-prisma-in-your-stack/01-rest.mdx @@ -43,7 +43,8 @@ datasource db { } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model Post { diff --git a/content/200-orm/050-overview/300-prisma-in-your-stack/03-fullstack.mdx b/content/200-orm/050-overview/300-prisma-in-your-stack/03-fullstack.mdx index df9b99e3ed..f0942db1e5 100644 --- a/content/200-orm/050-overview/300-prisma-in-your-stack/03-fullstack.mdx +++ b/content/200-orm/050-overview/300-prisma-in-your-stack/03-fullstack.mdx @@ -41,7 +41,8 @@ datasource db { } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model Post { diff --git a/content/200-orm/050-overview/300-prisma-in-your-stack/04-is-prisma-an-orm.mdx b/content/200-orm/050-overview/300-prisma-in-your-stack/04-is-prisma-an-orm.mdx index 9ae264f8c9..f642ebd85c 100644 --- a/content/200-orm/050-overview/300-prisma-in-your-stack/04-is-prisma-an-orm.mdx +++ b/content/200-orm/050-overview/300-prisma-in-your-stack/04-is-prisma-an-orm.mdx @@ -228,11 +228,11 @@ As an example, here's a Prisma schema for a blog: ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model Post { @@ -308,7 +308,8 @@ datasource db { } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` @@ -338,7 +339,8 @@ datasource db { } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model Post { @@ -380,7 +382,7 @@ So far, the article covered the concepts behind Prisma ORM, its implementation o Accessing the database with Prisma Client happens through the query methods it exposes. All queries return plain old JavaScript objects. Given the blog schema from above, fetching a user looks as follows: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() 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 323f9ca92c..822925c2ad 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 @@ -18,7 +18,7 @@ As of [v6.15.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without ```prisma generator client { - provider = "prisma-client-js" // or "prisma-client" + provider = "prisma-client" output = "../src/generated/prisma" engineType = "client" // no Rust engine } @@ -102,7 +102,7 @@ Earlier versions of Prisma ORM required you to first instantiate the driver itse ```typescript import { createClient } from '@libsql/client' import { PrismaLibSQL } from '@prisma/adapter-libsql' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' // Old way of using driver adapters (before 6.6.0) const driver = createClient({ @@ -137,7 +137,7 @@ When using Prisma ORM's built-in drivers, the connection string is read from the 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 -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import { PrismaPg } from '@prisma/adapter-pg' const adapter = new PrismaPg({ connectionString: env.DATABASE_URL }) @@ -154,7 +154,7 @@ Let's assume you had `output` in your Prisma schema set to `../src/generated/cli ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../src/generated/client" } ``` diff --git a/content/200-orm/050-overview/500-databases/300-postgresql.mdx b/content/200-orm/050-overview/500-databases/300-postgresql.mdx index fc4144ba28..0da3517e0b 100644 --- a/content/200-orm/050-overview/500-databases/300-postgresql.mdx +++ b/content/200-orm/050-overview/500-databases/300-postgresql.mdx @@ -25,14 +25,32 @@ To connect to a PostgreSQL database server, you need to configure a [`datasource ```prisma file=schema.prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` +The database connection URL is configured in `prisma.config.ts`: + +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + + + +**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell. + + + The fields passed to the `datasource` block are: - `provider`: Specifies the `postgresql` data source connector. -- `url`: Specifies the [connection URL](#connection-url) for the PostgreSQL database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +- The `url` field is configured in `prisma.config.ts` and specifies the [connection URL](#connection-url) for the PostgreSQL database server. ## Using the `node-postgres` driver @@ -56,7 +74,7 @@ Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ```ts import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const connectionString = `${process.env.DATABASE_URL}` diff --git a/content/200-orm/050-overview/500-databases/400-mysql.mdx b/content/200-orm/050-overview/500-databases/400-mysql.mdx index d9b7033275..ac2e4ff1da 100644 --- a/content/200-orm/050-overview/500-databases/400-mysql.mdx +++ b/content/200-orm/050-overview/500-databases/400-mysql.mdx @@ -16,14 +16,32 @@ To connect to a MySQL database server, you need to configure a [`datasource`](/o ```prisma file=schema.prisma showLineNumbers datasource db { provider = "mysql" - url = env("DATABASE_URL") } ``` +The database connection URL is configured in `prisma.config.ts`: + +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + + + +**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell. + + + The fields passed to the `datasource` block are: - `provider`: Specifies the `mysql` data source connector, which is used both for MySQL and MariaDB. -- `url`: Specifies the [connection URL](#connection-url) for the MySQL database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +- The `url` field is configured in `prisma.config.ts` and specifies the [connection URL](#connection-url) for the MySQL database server. ## Using the `mariadb` driver diff --git a/content/200-orm/050-overview/500-databases/500-sqlite.mdx b/content/200-orm/050-overview/500-databases/500-sqlite.mdx index db904f7aa8..1e27d3911b 100644 --- a/content/200-orm/050-overview/500-databases/500-sqlite.mdx +++ b/content/200-orm/050-overview/500-databases/500-sqlite.mdx @@ -46,10 +46,10 @@ npm install @prisma/adapter-better-sqlite3 Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ORM's driver adapter to the `PrismaClient` constructor: ```ts -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'; +import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'; import { PrismaClient } from './generated/prisma'; -const adapter = new PrismaBetterSQLite3({ +const adapter = new PrismaBetterSqlite3({ url: "file:./prisma/dev.db" }); const prisma = new PrismaClient({ adapter }); @@ -64,10 +64,10 @@ By default, driver adapters store `DateTime` values as **ISO 8601 strings**, whi However, if you need **100% backward compatibility** with Prisma ORM's native SQLite driver (for example, when migrating an existing database), you should use the `unixepoch-ms` format, which stores timestamps as the number of milliseconds since the Unix epoch: ```ts -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'; +import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'; import { PrismaClient } from './generated/prisma'; -const adapter = new PrismaBetterSQLite3({ +const adapter = new PrismaBetterSqlite3({ url: "file:./prisma/dev.db" }, { timestampFormat: 'unixepoch-ms' diff --git a/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx b/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx index b118b92b32..3c68496ba3 100644 --- a/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx +++ b/content/200-orm/050-overview/500-databases/800-sql-server/index.mdx @@ -15,14 +15,32 @@ To connect to a Microsoft SQL Server database, you need to configure a [`datasou ```prisma file=schema.prisma showLineNumbers datasource db { provider = "sqlserver" - url = env("DATABASE_URL") } ``` +The database connection URL is configured in `prisma.config.ts`: + +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + + + +**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell. + + + The fields passed to the `datasource` block are: - `provider`: Specifies the `sqlserver` data source connector. -- `url`: Specifies the [connection URL](#connection-details) for the Microsoft SQL Server database. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +- The `url` field is configured in `prisma.config.ts` and specifies the [connection URL](#connection-details) for the Microsoft SQL Server database. ## Using the `node-mssql` driver @@ -47,7 +65,7 @@ Now, when you instantiate Prisma Client, you need to pass an instance of Prisma ```ts import { PrismaMssql } from '@prisma/adapter-mssql' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const config = { server: 'localhost', 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 3d3bdf18b9..c3ae1c6f46 100644 --- a/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx +++ b/content/200-orm/050-overview/500-databases/840-cockroachdb.mdx @@ -99,14 +99,32 @@ To connect to a CockroachDB database server, you need to configure a [`datasourc ```prisma file=schema.prisma showLineNumbers datasource db { provider = "cockroachdb" - url = env("DATABASE_URL") } ``` +The database connection URL is configured in `prisma.config.ts`: + +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('DATABASE_URL'), + }, +}) +``` + + + +**Note**: When using Prisma CLI commands, environment variables are not automatically loaded. You'll need to use a package like `dotenv` to load environment variables from a `.env` file, or ensure your environment variables are set in your shell. + + + The fields passed to the `datasource` block are: - `provider`: Specifies the `cockroachdb` data source connector. -- `url`: Specifies the [connection URL](#connection-details) for the CockroachDB database server. In this case, an [environment variable is used](/orm/prisma-schema/overview#accessing-environment-variables-from-the-schema) to provide the connection URL. +- The `url` field is configured in `prisma.config.ts` and specifies the [connection URL](#connection-details) for the CockroachDB database server. diff --git a/content/200-orm/050-overview/500-databases/850-planetscale.mdx b/content/200-orm/050-overview/500-databases/850-planetscale.mdx index f000a80a33..8026411eaf 100644 --- a/content/200-orm/050-overview/500-databases/850-planetscale.mdx +++ b/content/200-orm/050-overview/500-databases/850-planetscale.mdx @@ -70,7 +70,6 @@ To enable emulation of relations in Prisma Client, set the `relationMode` field ```prisma file=schema.prisma datasource db { provider = "mysql" - url = env("DATABASE_URL") relationMode = "prisma" } ``` @@ -269,8 +268,8 @@ In order to use the shard key attributes, you need to specify the `shardKeys` Pr ```prisma generator client { - provider = "prisma-client-js" - output = "../generated/prisma" + provider = "prisma-client" + output = "./generated/prisma" previewFeatures = ["shardKeys"] } ``` @@ -336,7 +335,7 @@ Update your Prisma Client instance to use the PlanetScale serverless driver: ```ts import { PrismaPlanetScale } from '@prisma/adapter-planetscale' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/prisma/client' import dotenv from 'dotenv' import { fetch as undiciFetch } from 'undici' diff --git a/content/200-orm/050-overview/500-databases/880-supabase.mdx b/content/200-orm/050-overview/500-databases/880-supabase.mdx index 9f338d42d4..3be5807f56 100644 --- a/content/200-orm/050-overview/500-databases/880-supabase.mdx +++ b/content/200-orm/050-overview/500-databases/880-supabase.mdx @@ -64,9 +64,6 @@ You can then update your `schema.prisma` to use the new direct URL: ```prisma file=schema.prisma highlight=4;add showLineNumbers datasource db { provider = "postgresql" - url = env("DATABASE_URL") - //add-next-line - directUrl = env("DIRECT_URL") } ``` diff --git a/content/200-orm/050-overview/500-databases/890-neon.mdx b/content/200-orm/050-overview/500-databases/890-neon.mdx index d5be0b9d74..af9a0e2272 100644 --- a/content/200-orm/050-overview/500-databases/890-neon.mdx +++ b/content/200-orm/050-overview/500-databases/890-neon.mdx @@ -63,9 +63,6 @@ You can then update your `schema.prisma` to use the new direct URL: ```prisma file=schema.prisma highlight=4;add showLineNumbers datasource db { provider = "postgresql" - url = env("DATABASE_URL") - //add-next-line - directUrl = env("DIRECT_URL") } ``` @@ -129,7 +126,7 @@ npm install @prisma/adapter-neon Update your Prisma Client instance: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import { PrismaNeon } from '@prisma/adapter-neon' import dotenv from 'dotenv' diff --git a/content/200-orm/050-overview/500-databases/900-turso.mdx b/content/200-orm/050-overview/500-databases/900-turso.mdx index d4bdb03925..193309fc5c 100644 --- a/content/200-orm/050-overview/500-databases/900-turso.mdx +++ b/content/200-orm/050-overview/500-databases/900-turso.mdx @@ -92,7 +92,7 @@ npm install @prisma/adapter-libsql Update your Prisma Client instance: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import { PrismaLibSQL } from '@prisma/adapter-libsql' const adapter = new PrismaLibSQL({ diff --git a/content/200-orm/050-overview/600-beyond-prisma-orm.mdx b/content/200-orm/050-overview/600-beyond-prisma-orm.mdx index bcb0a883e0..d3640fb297 100644 --- a/content/200-orm/050-overview/600-beyond-prisma-orm.mdx +++ b/content/200-orm/050-overview/600-beyond-prisma-orm.mdx @@ -33,7 +33,7 @@ Scale to millions of queries per day without infrastructure changes. Efficiently Accelerate integrates seamlessly with your Prisma ORM project through the `@prisma/extension-accelerate` client extension. Get started quickly with our [setup guide](/accelerate/getting-started) and instantly access full edge environment support, connection pooling, and global caching. ```tsx -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import { withAccelerate } from '@prisma/extension-accelerate' // 1. Extend your Prisma Client with the Accelerate extension diff --git a/content/200-orm/100-prisma-schema/10-overview/index.mdx b/content/200-orm/100-prisma-schema/10-overview/index.mdx index 447ed608e5..462d421657 100644 --- a/content/200-orm/100-prisma-schema/10-overview/index.mdx +++ b/content/200-orm/100-prisma-schema/10-overview/index.mdx @@ -37,11 +37,11 @@ The following is an example of a Prisma Schema that specifies: ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model User { @@ -144,7 +144,6 @@ Environment variables can be accessed using the `env()` function: ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` diff --git a/content/200-orm/100-prisma-schema/20-data-model/10-models.mdx b/content/200-orm/100-prisma-schema/20-data-model/10-models.mdx index f8b2711c3e..2a36f0c9da 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/10-models.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/10-models.mdx @@ -20,11 +20,11 @@ The following schema describes a blogging platform - the data model definition i ```prisma highlight=10-46;normal datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } //highlight-start @@ -189,7 +189,7 @@ const user = await prisma.user.create({ ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient({}) diff --git a/content/200-orm/100-prisma-schema/20-data-model/20-relations/410-referential-actions/index.mdx b/content/200-orm/100-prisma-schema/20-data-model/20-relations/410-referential-actions/index.mdx index bbef7dc445..74bfa2bb9b 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/20-relations/410-referential-actions/index.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/20-relations/410-referential-actions/index.mdx @@ -472,7 +472,7 @@ Prior to upgrading and enabling the referential actions **preview feature**, the > "The change you are trying to make would violate the required relation '\{relation_name}' between the \{model_a_name\} and \{model_b_name\} models." ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() @@ -500,7 +500,7 @@ To make sure you are checking for the correct errors in your code, modify your c > "Foreign key constraint failed on the field: \{field_name\}" ```ts highlight=14;delete|15;add -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() diff --git a/content/200-orm/100-prisma-schema/20-data-model/20-relations/420-relation-mode.mdx b/content/200-orm/100-prisma-schema/20-data-model/20-relations/420-relation-mode.mdx index 99aa146c36..669674a0bf 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/20-relations/420-relation-mode.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/20-relations/420-relation-mode.mdx @@ -88,7 +88,6 @@ To set the relation mode, add the `relationMode` field in the `datasource` block ```prisma file=schema.prisma highlight=4,9;add showLineNumbers datasource db { provider = "mysql" - url = env("DATABASE_URL") //add-next-line relationMode = "prisma" } @@ -213,7 +212,6 @@ If you do not add the index manually, queries might require full table scans. Th ```prisma file=schema.prisma showLineNumbers datasource db { provider = "mysql" - url = env("DATABASE_URL") relationMode = "prisma" } diff --git a/content/200-orm/100-prisma-schema/20-data-model/30-indexes.mdx b/content/200-orm/100-prisma-schema/20-data-model/30-indexes.mdx index 66ac00544d..0c11afd2aa 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/30-indexes.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/30-indexes.mdx @@ -491,7 +491,8 @@ To enable the `fullTextIndex` preview feature, add the `fullTextIndex` feature f ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["fullTextIndex"] } ``` diff --git a/content/200-orm/100-prisma-schema/20-data-model/40-views.mdx b/content/200-orm/100-prisma-schema/20-data-model/40-views.mdx index ab3467c8dd..f2c479674f 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/40-views.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/40-views.mdx @@ -31,6 +31,7 @@ Support for views is currently in an early preview. To enable the `views` previe ```prisma file=schema.prisma highlight=3;add showLineNumbers generator client { provider = "prisma-client" + output = "./generated" //add-next-line previewFeatures = ["views"] } diff --git a/content/200-orm/100-prisma-schema/20-data-model/60-multi-schema.mdx b/content/200-orm/100-prisma-schema/20-data-model/60-multi-schema.mdx index 213aca8ec7..6c8568acbe 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/60-multi-schema.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/60-multi-schema.mdx @@ -28,11 +28,11 @@ To use multiple database schemas in your Prisma schema file, add the names of yo ```prisma file=schema.prisma generator client { provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") //add-next-line schemas = ["base", "shop"] } diff --git a/content/200-orm/100-prisma-schema/20-data-model/65-externally-managed-tables.mdx b/content/200-orm/100-prisma-schema/20-data-model/65-externally-managed-tables.mdx index 05851a8b33..bf8cdfb38c 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/65-externally-managed-tables.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/65-externally-managed-tables.mdx @@ -119,7 +119,8 @@ Assume you have the following Prisma schema which only contains the `posts` tabl ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" // ... } diff --git a/content/200-orm/100-prisma-schema/20-data-model/70-unsupported-database-features.mdx b/content/200-orm/100-prisma-schema/20-data-model/70-unsupported-database-features.mdx index 5c5476d85c..cc27bd16c3 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/70-unsupported-database-features.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/70-unsupported-database-features.mdx @@ -58,18 +58,19 @@ In Prisma ORM versions 4.5.0 and later, you can then activate the extension by d ```prisma file=schema.prisma highlight=3,9;add showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" //add-next-line previewFeatures = ["postgresqlExtensions"] } datasource db { provider = "postgresql" - url = env("DATABASE_URL") //add-next-line extensions = [pgcrypto] } ``` +``` In earlier versions of Prisma ORM, you must instead run a SQL command to activate the extension: diff --git a/content/200-orm/100-prisma-schema/20-data-model/80-table-inheritance.mdx b/content/200-orm/100-prisma-schema/20-data-model/80-table-inheritance.mdx index 5824300c6b..e3aad67fde 100644 --- a/content/200-orm/100-prisma-schema/20-data-model/80-table-inheritance.mdx +++ b/content/200-orm/100-prisma-schema/20-data-model/80-table-inheritance.mdx @@ -141,7 +141,7 @@ When querying for videos and articles like that, TypeScript will still only reco If you want to have type safety for these objects, you need to define dedicated types for them. You can do this, for example, by using the generated `Activity` type and the TypeScript `Omit` utility type to remove properties from it: ```ts -import { Activity } from '@prisma/client' +import { Activity } from '../prisma/generated/client' type Video = Omit type Article = Omit @@ -272,7 +272,7 @@ import { Video as VideoDB, Article as ArticleDB, Activity, -} from '@prisma/client' +} from '../prisma/generated/client' type Video = Omit type Article = Omit @@ -281,7 +281,7 @@ type Article = Omit Once these types are defined, you can define mapping functions to convert the types you receive from the queries above into the desired `Video` and `Article` types. Here's the example for the `Video` type: ```ts -import { Prisma, Video as VideoDB, Activity } from '@prisma/client' +import { Prisma, Video as VideoDB, Activity } from '../prisma/generated/client' type Video = Omit diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/005-introduction.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/005-introduction.mdx index 7c8f5d58f0..3b6c98efa0 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/005-introduction.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/005-introduction.mdx @@ -47,12 +47,11 @@ In order to set up Prisma Client, you need a [Prisma schema file](/orm/prisma-sc ```prisma file=schema.prisma datasource db { - url = env("DATABASE_URL") provider = "postgresql" } generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../src/generated/prisma" } @@ -163,7 +162,7 @@ All Prisma Client methods return an instance of [`PrismaPromise`](/orm/reference ### 5. Evolving your application -Whenever you make changes to your database that are reflected in the Prisma schema, you need to manually re-generate Prisma Client to update the generated code in the `node_modules/.prisma/client` directory: +Whenever you make changes to your database that are reflected in the Prisma schema, you need to manually re-generate Prisma Client to update the generated code in your output directory: ``` prisma generate diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/010-generating-prisma-client.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/010-generating-prisma-client.mdx index 8e7d257bf2..8dbaced9d4 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/010-generating-prisma-client.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/010-generating-prisma-client.mdx @@ -18,7 +18,8 @@ If Prisma ORM's Rust engine binaries cause large bundle sizes, slow builds, or d ```prisma generator client { - provider = "prisma-client-js" // or "prisma-client" + provider = "prisma-client" + output = "./generated" engineType = "client" } ``` @@ -49,7 +50,7 @@ To generate and instantiate Prisma Client: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "app/generated/prisma/client" } ``` @@ -100,7 +101,7 @@ You can also specify a custom `output` path on the `generator` configuration, fo ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../src/generated/client" } ``` @@ -114,7 +115,7 @@ After running `prisma generate` for that schema file, the Prisma Client package To import the `PrismaClient` from a custom location (for example, from a file named `./src/script.ts`): ```ts -import { PrismaClient } from './generated/client' +import { PrismaClient } from '../src/generated/client' ``` :::note @@ -169,7 +170,7 @@ export * from '.prisma/client' This means that you still import `@prisma/client` in your own `.ts` files: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' ``` Prisma Client is generated from your Prisma schema and is unique to your project. Each time you change the schema (for example, by performing a [schema migration](/orm/prisma-migrate)) and run `prisma generate`, Prisma Client's code changes: diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/015-instantiate-prisma-client.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/015-instantiate-prisma-client.mdx index 5b913ccb38..48da945dac 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/015-instantiate-prisma-client.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/015-instantiate-prisma-client.mdx @@ -12,7 +12,7 @@ The following example demonstrates how to import and instantiate your [generated ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() ``` @@ -22,7 +22,7 @@ const prisma = new PrismaClient() ```js -const { PrismaClient } = require('@prisma/client') +const { PrismaClient } = require('../prisma/generated/client') const prisma = new PrismaClient() ``` diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/100-connection-management.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/100-connection-management.mdx index 241f4a247b..b647cb5858 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/100-connection-management.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/100-connection-management.mdx @@ -67,7 +67,7 @@ One scenario where you should call `$disconnect()` explicitly is where a script: The following script creates a new instance of `PrismaClient`, performs a task, and then disconnects - which closes the connection pool: ```ts highlight=19;normal -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() const emailService = new EmailService() diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/115-connection-pool.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/115-connection-pool.mdx index ba25506e73..91b8117f42 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/115-connection-pool.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/115-connection-pool.mdx @@ -29,7 +29,7 @@ As of [v6.16.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without ```prisma generator client { - provider = "prisma-client-js" // or "prisma-client" + provider = "prisma-client" output = "../src/generated/prisma" engineType = "client" // no Rust engine } @@ -96,7 +96,7 @@ For example, consider the following Prisma Client instance and invocation: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient({ log: ['info'], @@ -135,7 +135,7 @@ Consider the following example: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/index.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/index.mdx index 4f9daf7d74..b43ba49511 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/index.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/050-databases-connections/index.mdx @@ -61,7 +61,7 @@ In **long-running** applications, we recommend that you: To re-use a single instance, create a module that exports a `PrismaClient` object: ```ts file=client.ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' let prisma = new PrismaClient() @@ -93,7 +93,7 @@ Frameworks like [Next.js](https://nextjs.org/) support hot reloading of changed As a workaround, you can store `PrismaClient` as a global variable in development environments only, as global variables are not reloaded: ```ts file=client.ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const globalForPrisma = globalThis as unknown as { prisma: PrismaClient } @@ -223,7 +223,7 @@ If the `connection_limit` is 1, this function is forced to send queries **serial Instantiate `PrismaClient` [outside the scope of the function handler](https://github.com/prisma/e2e-tests/blob/5d1041d3f19245d3d237d959eca94d1d796e3a52/platforms/serverless-lambda/index.ts#L3) to increase the chances of reuse. As long as the handler remains 'warm' (in use), the connection is potentially reusable: ```ts highlight=3;normal -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const client = new PrismaClient() @@ -273,7 +273,7 @@ As of [v6.16.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without ```prisma generator client { - provider = "prisma-client-js" // or "prisma-client" + provider = "prisma-client" output = "../src/generated/prisma" engineType = "client" // no Rust engine } @@ -353,7 +353,6 @@ You can then update your `schema.prisma` to use the new direct URL: ```prisma file=schema.prisma highlight=4;add showLineNumbers datasource db { provider = "postgresql" - url = env("DATABASE_URL") //add-next-line directUrl = env("DIRECT_URL") } diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/200-read-replicas.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/200-read-replicas.mdx index ef695f72d3..619d0a798d 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/200-read-replicas.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/200-read-replicas.mdx @@ -26,7 +26,7 @@ Initialize the extension by extending your Prisma Client instance and provide th ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import { readReplicas } from '@prisma/extension-read-replicas' const prisma = new PrismaClient().$extends( diff --git a/content/200-orm/200-prisma-client/000-setup-and-configuration/300-no-rust-engine.mdx b/content/200-orm/200-prisma-client/000-setup-and-configuration/300-no-rust-engine.mdx index a23c2016fd..348a0e6fc3 100644 --- a/content/200-orm/200-prisma-client/000-setup-and-configuration/300-no-rust-engine.mdx +++ b/content/200-orm/200-prisma-client/000-setup-and-configuration/300-no-rust-engine.mdx @@ -100,7 +100,7 @@ Finally, instantiate Prisma Client which you can do using the driver adapter and ```typescript import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from './generated/prisma' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) @@ -108,16 +108,16 @@ const prisma = new PrismaClient({ adapter }) ```typescript -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'; -import { PrismaClient } from './generated/prisma'; +import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'; +import { PrismaClient } from '../generated/prisma/client'; -const adapter = new PrismaBetterSQLite3({ url: process.env.DATABASE_URL }) +const adapter = new PrismaBetterSqlite3({ url: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }); ``` ```typescript -import { PrismaClient } from './generated/prisma' +import { PrismaClient } from '../generated/prisma/client' import { PrismaD1 } from '@prisma/adapter-d1' export interface Env { @@ -141,7 +141,7 @@ export default { ```typescript import { PrismaMariaDb } from '@prisma/adapter-mariadb'; -import { PrismaClient } from './generated/prisma'; +import { PrismaClient } from '../generated/prisma/client'; const adapter = new PrismaMariaDb({ host: "localhost", @@ -154,7 +154,7 @@ const prisma = new PrismaClient({ adapter }); ```typescript import { PrismaPlanetScale } from '@prisma/adapter-planetscale' -import { PrismaClient } from './generated/prisma' +import { PrismaClient } from '../generated/prisma/client' import { fetch as undiciFetch } from 'undici' const adapter = new PrismaPlanetScale({ url: process.env.DATABASE_URL, fetch: undiciFetch }) @@ -164,7 +164,7 @@ const prisma = new PrismaClient({ adapter }) ```typescript import { PrismaMSSQL } from '@prisma/adapter-mssql'; -import { PrismaClient } from './generated/prisma'; +import { PrismaClient } from '../generated/prisma/client'; const sqlConfig = { user: process.env.DB_USER, @@ -189,7 +189,7 @@ const prisma = new PrismaClient({ adapter }); ```typescript import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from './generated/prisma' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) @@ -197,7 +197,7 @@ const prisma = new PrismaClient({ adapter }) ```typescript -import { PrismaClient } from './generated/prisma' +import { PrismaClient } from '../generated/prisma/client' import { PrismaNeon } from '@prisma/adapter-neon' import dotenv from 'dotenv' @@ -241,7 +241,7 @@ npx prisma generate Import and instantiate Prisma Client with the Accelerate extension: ```typescript -import { PrismaClient } from "./generated/prisma"; +import { PrismaClient } from "../generated/prisma/client"; import { withAccelerate } from "@prisma/extension-accelerate"; const prisma = new PrismaClient().$extends(withAccelerate()); @@ -268,7 +268,7 @@ Usage of the new architecture requires the `driverAdapters` and `queryCompiler` ```prisma file=schema.prisma generator client { - provider = "prisma-client-js" // or `prisma-client` + provider = "prisma-client" previewFeatures = ["queryCompiler", "driverAdapters"] output = "../generated/prisma" } @@ -337,7 +337,7 @@ Finally, you need to instantiate Prisma Client which you can do using the driver ```typescript import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from './generated/prisma' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) @@ -345,16 +345,16 @@ const prisma = new PrismaClient({ adapter }) ```typescript -import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'; -import { PrismaClient } from './generated/prisma'; +import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'; +import { PrismaClient } from '../generated/prisma/client'; -const adapter = new PrismaBetterSQLite3({ url: process.env.DATABASE_URL }) +const adapter = new PrismaBetterSqlite3({ url: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }); ``` ```typescript -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../generated/prisma/client' import { PrismaD1 } from '@prisma/adapter-d1' export interface Env { @@ -378,7 +378,7 @@ export default { ```typescript import { PrismaMariaDb } from '@prisma/adapter-mariadb'; -import { PrismaClient } from './generated/prisma'; +import { PrismaClient } from '../generated/prisma/client'; const adapter = new PrismaMariaDb({ host: "localhost", @@ -391,7 +391,7 @@ const prisma = new PrismaClient({ adapter }); ```typescript import { PrismaPlanetScale } from '@prisma/adapter-planetscale' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../generated/prisma/client' import { fetch as undiciFetch } from 'undici' const adapter = new PrismaPlanetScale({ url: process.env.DATABASE_URL, fetch: undiciFetch }) @@ -401,7 +401,7 @@ const prisma = new PrismaClient({ adapter }) ```typescript import { PrismaMSSQL } from '@prisma/adapter-mssql'; -import { PrismaClient } from './generated/prisma'; +import { PrismaClient } from '../generated/prisma/client'; const sqlConfig = { user: process.env.DB_USER, @@ -426,7 +426,7 @@ const prisma = new PrismaClient({ adapter }); ```typescript import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from './generated/prisma' +import { PrismaClient } from '../generated/prisma/client' const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }) const prisma = new PrismaClient({ adapter }) @@ -434,7 +434,7 @@ const prisma = new PrismaClient({ adapter }) ```typescript -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../generated/prisma/client' import { PrismaNeon } from '@prisma/adapter-neon' import dotenv from 'dotenv' diff --git a/content/200-orm/200-prisma-client/100-queries/030-crud.mdx b/content/200-orm/200-prisma-client/100-queries/030-crud.mdx index 09dba52754..5263fc26af 100644 --- a/content/200-orm/200-prisma-client/100-queries/030-crud.mdx +++ b/content/200-orm/200-prisma-client/100-queries/030-crud.mdx @@ -32,11 +32,11 @@ All examples are based on the following schema: ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model ExtendedProfile { @@ -191,7 +191,7 @@ The user's `id` is auto-generated, and your schema determines [which fields are The following example produces an identical result, but creates a `UserCreateInput` variable named `user` _outside_ the context of the `create()` query. After completing a simple check ("Should posts be included in this `create()` query?"), the `user` variable is passed into the query: ```ts -import { PrismaClient, Prisma } from '@prisma/client' +import { PrismaClient, Prisma } from '../prisma/generated/client' const prisma = new PrismaClient() diff --git a/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx b/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx index 7a8fab2b4f..daffbf41a1 100644 --- a/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx +++ b/content/200-orm/200-prisma-client/100-queries/037-relation-queries.mdx @@ -30,7 +30,8 @@ Because the `relationLoadStrategy` option is currently in Preview, you need to e ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["relationJoins"] } ``` diff --git a/content/200-orm/200-prisma-client/100-queries/050-filtering-and-sorting.mdx b/content/200-orm/200-prisma-client/100-queries/050-filtering-and-sorting.mdx index 813f6605b6..87fc1bf2e2 100644 --- a/content/200-orm/200-prisma-client/100-queries/050-filtering-and-sorting.mdx +++ b/content/200-orm/200-prisma-client/100-queries/050-filtering-and-sorting.mdx @@ -394,7 +394,8 @@ This feature is further explain in [the PostgreSQL documentation](https://www.po ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["fullTextSearchPostgres"] } ``` diff --git a/content/200-orm/200-prisma-client/100-queries/058-transactions.mdx b/content/200-orm/200-prisma-client/100-queries/058-transactions.mdx index 63b93505b5..56bc876db3 100644 --- a/content/200-orm/200-prisma-client/100-queries/058-transactions.mdx +++ b/content/200-orm/200-prisma-client/100-queries/058-transactions.mdx @@ -235,7 +235,7 @@ In the example below, Alice and Bob each have $100 in their account. If they try Alice is expected to be able to make 1 transfer for $100 while the other transfer would be rejected. This would result in Alice having $0 and Bob having $200. ```tsx -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() function transfer(from: string, to: string, amount: number) { @@ -453,7 +453,7 @@ To avoid transaction write conflicts and deadlocks on a transaction: 2. In your application code, add a retry around your transaction to handle any P2034 errors, as shown in this example: ```ts - import { Prisma, PrismaClient } from '@prisma/client' + import { Prisma, PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() async function main() { @@ -1324,7 +1324,7 @@ In the example below, Alice and Bob each have $100 in their account. If they try The expected outcome would be for Alice to make 1 transfer for $100 and the other transfer would be rejected. This would result in Alice having $0 and Bob having $200. ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() async function transfer(from: string, to: string, amount: number) { diff --git a/content/200-orm/200-prisma-client/100-queries/060-full-text-search.mdx b/content/200-orm/200-prisma-client/100-queries/060-full-text-search.mdx index ef473c95b8..d50bb74df0 100644 --- a/content/200-orm/200-prisma-client/100-queries/060-full-text-search.mdx +++ b/content/200-orm/200-prisma-client/100-queries/060-full-text-search.mdx @@ -21,7 +21,8 @@ The full-text search API is currently a Preview feature. To enable this feature, ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["fullTextSearchPostgres"] } ``` @@ -199,7 +200,8 @@ In the following example, one full text index is added to the `content` field of ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model Blog { diff --git a/content/200-orm/200-prisma-client/100-queries/061-custom-validation.mdx b/content/200-orm/200-prisma-client/100-queries/061-custom-validation.mdx index ecc05879aa..240ed5b19b 100644 --- a/content/200-orm/200-prisma-client/100-queries/061-custom-validation.mdx +++ b/content/200-orm/200-prisma-client/100-queries/061-custom-validation.mdx @@ -30,7 +30,7 @@ Query extensions do not currently work for nested operations. In this example, v ```ts copy -import { PrismaClient, Prisma } from '@prisma/client' +import { PrismaClient, Prisma } from '../prisma/generated/client' import { z } from 'zod' /** @@ -114,11 +114,11 @@ main() ```prisma copy datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model Product { diff --git a/content/200-orm/200-prisma-client/100-queries/062-computed-fields.mdx b/content/200-orm/200-prisma-client/100-queries/062-computed-fields.mdx index a923a0aff8..d1f525afb8 100644 --- a/content/200-orm/200-prisma-client/100-queries/062-computed-fields.mdx +++ b/content/200-orm/200-prisma-client/100-queries/062-computed-fields.mdx @@ -19,7 +19,7 @@ The following example illustrates how to create a [Prisma Client extension](/orm ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient().$extends({ result: { @@ -68,11 +68,11 @@ main() ```prisma copy datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model User { diff --git a/content/200-orm/200-prisma-client/100-queries/064-custom-models.mdx b/content/200-orm/200-prisma-client/100-queries/064-custom-models.mdx index 4d5a576e1f..a51ed1c994 100644 --- a/content/200-orm/200-prisma-client/100-queries/064-custom-models.mdx +++ b/content/200-orm/200-prisma-client/100-queries/064-custom-models.mdx @@ -24,7 +24,7 @@ The following example demonstrates how to create a Prisma Client extension that ```tsx import bcrypt from 'bcryptjs' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient().$extends({ model: { @@ -67,11 +67,11 @@ async function main() { ```prisma file="prisma/schema.prisma" copy datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } model User { diff --git a/content/200-orm/200-prisma-client/150-using-raw-sql/300-safeql.mdx b/content/200-orm/200-prisma-client/150-using-raw-sql/300-safeql.mdx index a899de290a..65d9323bf2 100644 --- a/content/200-orm/200-prisma-client/150-using-raw-sql/300-safeql.mdx +++ b/content/200-orm/200-prisma-client/150-using-raw-sql/300-safeql.mdx @@ -44,14 +44,14 @@ If you haven't already, enable the `postgresqlExtensions` Preview feature and ad ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" //add-next-line previewFeatures = ["postgresqlExtensions"] } datasource db { provider = "postgresql" - url = env("DATABASE_URL") //add-next-line extensions = [postgis] } diff --git a/content/200-orm/200-prisma-client/200-special-fields-and-types/080-null-and-undefined.mdx b/content/200-orm/200-prisma-client/200-special-fields-and-types/080-null-and-undefined.mdx index 6af305057d..efafcddf81 100644 --- a/content/200-orm/200-prisma-client/200-special-fields-and-types/080-null-and-undefined.mdx +++ b/content/200-orm/200-prisma-client/200-special-fields-and-types/080-null-and-undefined.mdx @@ -23,7 +23,8 @@ To enable this feature, add the following to your Prisma schema: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["strictUndefinedChecks"] } ``` 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 ad796c8c04..5929d1683e 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 @@ -986,7 +986,8 @@ Prisma's `Json` fields are untyped by default. To add strong typing, you can use ```prisma file=schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } generator json { diff --git a/content/200-orm/200-prisma-client/400-type-safety/830-prisma-type-system.mdx b/content/200-orm/200-prisma-client/400-type-safety/830-prisma-type-system.mdx index 17a6241106..b7d4854e2b 100644 --- a/content/200-orm/200-prisma-client/400-type-safety/830-prisma-type-system.mdx +++ b/content/200-orm/200-prisma-client/400-type-safety/830-prisma-type-system.mdx @@ -17,7 +17,6 @@ Prisma ORM uses _types_ to define the kind of data that a field can hold. To mak ```prisma file=schema.prisma showLineNumbers datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model Post { diff --git a/content/200-orm/200-prisma-client/500-deployment/201-serverless/300-deploy-to-vercel.mdx b/content/200-orm/200-prisma-client/500-deployment/201-serverless/300-deploy-to-vercel.mdx index f5717fed5f..baedae6a6b 100644 --- a/content/200-orm/200-prisma-client/500-deployment/201-serverless/300-deploy-to-vercel.mdx +++ b/content/200-orm/200-prisma-client/500-deployment/201-serverless/300-deploy-to-vercel.mdx @@ -148,7 +148,7 @@ Use `attachDatabasePool` together with [Prisma's driver adapters](/orm/overview/ import { Pool } from 'pg' import { attachDatabasePool } from '@vercel/functions' import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/client' const pool = new Pool({ connectionString: process.env.POSTGRES_URL }) diff --git a/content/200-orm/200-prisma-client/500-deployment/201-serverless/400-deploy-to-aws-lambda.mdx b/content/200-orm/200-prisma-client/500-deployment/201-serverless/400-deploy-to-aws-lambda.mdx index fc386c5aa4..0d17dffc3a 100644 --- a/content/200-orm/200-prisma-client/500-deployment/201-serverless/400-deploy-to-aws-lambda.mdx +++ b/content/200-orm/200-prisma-client/500-deployment/201-serverless/400-deploy-to-aws-lambda.mdx @@ -357,7 +357,7 @@ While SST supports `.env` files, [it is not recommended](https://v2.sst.dev/conf The SST guide [available here](https://v2.sst.dev/config#overview) is a step-by-step guide to get started with `Config`. Assuming you have created a new secret called `DATABASE_URL` and have [bound that secret to your app](https://v2.sst.dev/config#bind-the-config), you can set up `PrismaClient` with the following: ```ts file=prisma.ts showLineNumbers -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/client' import { Config } from 'sst/node/config' const globalForPrisma = global as unknown as { prisma: PrismaClient } 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 index c12f9ddf1e..4826ce9d98 100644 --- 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 @@ -73,7 +73,7 @@ npm i @prisma/extension-accelerate And extend `PrismaClient` with the extension in your application code: ```typescript -import { PrismaClient } from "@prisma/client/edge"; +import { PrismaClient } from "./generated/client"; import { withAccelerate } from "@prisma/extension-accelerate"; export interface Env { @@ -123,15 +123,25 @@ If your application uses PostgreSQL, we recommend using [Prisma Postgres](/postg ### 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: +First, ensure that your `datasource` block in your Prisma schema is configured correctly. Database connection URLs are configured in `prisma.config.ts`: ```prisma datasource db { provider = "postgresql" // this might also be `mysql` or another value depending on your database - url = env("DATABASE_URL") } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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/#local-development-with-secrets) locally. @@ -253,19 +263,30 @@ If you don't have a project to deploy, follow the instructions in the [Prerequis ::: -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: +First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`: ```prisma file=schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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 @@ -328,7 +349,7 @@ npm run env -- npx prisma migrate dev --name init 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 { PrismaClient } from './generated/client' import { PrismaPg } from '@prisma/adapter-pg' export default { @@ -412,16 +433,27 @@ First, ensure that the database connection is configured properly. In your Prism ```prisma file=schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "mysql" - url = env("DATABASE_URL") relationMode = "prisma" // required for PlanetScale (as by default foreign keys are disabled) } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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 @@ -470,7 +502,7 @@ npm run env -- npx prisma db push 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 { PrismaClient } from './generated/client' import { PrismaPlanetScale } from '@prisma/adapter-planetscale' export default { @@ -538,19 +570,30 @@ If you don't have a project to deploy, follow the instructions in the [Prerequis ::: -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: +First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`: ```prisma file=schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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 @@ -599,7 +642,7 @@ npm run env -- npx prisma migrate dev --name init 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 { PrismaClient } from './generated/client' import { PrismaNeon } from '@prisma/adapter-neon' export default { 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 index bab4e03d21..5c0fbc3d26 100644 --- 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 @@ -87,15 +87,25 @@ If your application uses PostgreSQL, we recommend using [Prisma Postgres](/postg ### 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: +First, ensure that your `datasource` block in your Prisma schema is configured correctly. Database connection URLs are configured in `prisma.config.ts`: ```prisma datasource db { provider = "postgresql" // this might also be `mysql` or another value depending on your database - url = env("DATABASE_URL") } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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)). @@ -159,13 +169,17 @@ model User { If you are using Vercel Postgres, you need to: - use the `@prisma/adapter-neon` database adapter 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 - } +- 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 configure these in `prisma.config.ts`: + ```ts file=prisma.config.ts + import { defineConfig, env } from 'prisma/config' + + export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + url: env('POSTGRES_PRISMA_URL'), // uses connection pooling + directUrl: env('POSTGRES_URL_NON_POOLING'), // uses a direct connection + }, + }) ``` #### 1. Configure Prisma schema & database connection @@ -176,20 +190,31 @@ If you don't have a project to deploy, follow the instructions in the [Prerequis ::: -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: +First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`: ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { - provider = "postgresql" - url = env("POSTGRES_PRISMA_URL") // uses connection pooling - directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection + provider = "postgresql" } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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: @@ -246,7 +271,7 @@ Here is a sample code snippet that you can use to instantiate `PrismaClient` and ```ts file=app/api/edge/route.ts showLineNumbers import { NextResponse } from 'next/server' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/client' import { PrismaNeon } from '@prisma/adapter-neon' export const runtime = 'nodejs' // can also be set to 'edge' @@ -301,20 +326,31 @@ If you don't have a project to deploy, follow the instructions in the [Prerequis ::: -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: +First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`: ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "mysql" - url = env("DATABASE_URL") relationMode = "prisma" // required for PlanetScale (as by default foreign keys are disabled) } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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 @@ -368,7 +404,7 @@ Here is a sample code snippet that you can use to instantiate `PrismaClient` and ```ts file=app/api/edge/route.ts showLineNumbers import { NextResponse } from 'next/server' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/client' import { PrismaPlanetScale } from '@prisma/adapter-planetscale' export const runtime = 'nodejs' // can also be set to 'edge' @@ -423,19 +459,30 @@ If you don't have a project to deploy, follow the instructions in the [Prerequis ::: -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: +First, ensure that the database connection is configured properly. Database connection URLs are configured in `prisma.config.ts`: ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` +```ts file=prisma.config.ts +import { defineConfig, env } from 'prisma/config' + +export default defineConfig({ + schema: 'prisma/schema.prisma', + datasource: { + 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 showLineNumbers @@ -489,7 +536,7 @@ Here is a sample code snippet that you can use to instantiate `PrismaClient` and ```ts file=app/api/edge/route.ts showLineNumbers import { NextResponse } from 'next/server' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/client' import { PrismaNeon } from '@prisma/adapter-neon' export const runtime = 'nodejs' // can also be set to 'edge' @@ -540,7 +587,7 @@ Use `attachDatabasePool` together with [Prisma's driver adapters](/orm/overview/ import { Pool } from 'pg' import { attachDatabasePool } from '@vercel/functions' import { PrismaPg } from '@prisma/adapter-pg' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from './generated/client' const pool = new Pool({ connectionString: process.env.POSTGRES_URL }) diff --git a/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx b/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx index 24c7af9c08..d47dfa0c7c 100644 --- a/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx +++ b/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx @@ -88,7 +88,6 @@ generator client { datasource db { provider = "postgresql" - url = env("DATABASE_URL") } //add-start @@ -147,7 +146,7 @@ You can now create a local Deno application. Create `index.ts` in the root folde ```ts file=index.ts import { serve } from "https://deno.land/std@0.140.0/http/server.ts"; import { withAccelerate } from "npm:@prisma/extension-accelerate"; -import { PrismaClient } from "./generated/prisma/client.ts"; +import { PrismaClient } from "../generated/prisma/client.ts"; const prisma = new PrismaClient().$extends(withAccelerate()); @@ -254,7 +253,7 @@ Add the following code in your `index.ts` file: ```ts file=index.ts import { serve } from "https://deno.land/std@0.140.0/http/server.ts"; import { withAccelerate } from "npm:@prisma/extension-accelerate"; -import { PrismaClient } from "./generated/prisma/client.ts"; +import { PrismaClient } from "../generated/prisma/client.ts"; const prisma = new PrismaClient().$extends(withAccelerate()); diff --git a/content/200-orm/200-prisma-client/600-observability-and-logging/240-metrics.mdx b/content/200-orm/200-prisma-client/600-observability-and-logging/240-metrics.mdx index cff5a46155..b7a01c0c4a 100644 --- a/content/200-orm/200-prisma-client/600-observability-and-logging/240-metrics.mdx +++ b/content/200-orm/200-prisma-client/600-observability-and-logging/240-metrics.mdx @@ -98,7 +98,8 @@ In the `generator` block of your `schema.prisma` file, enable the `metrics` feat ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["metrics"] } ``` @@ -512,7 +513,7 @@ For more information, read the Prometheus documentation on [metric types](https: In the majority of cases, Prometheus must scrape an endpoint to retrieve metrics. The following example shows how to send data with `Express.js`: ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import express, { Request, Response } from 'express' const app = express() @@ -532,7 +533,7 @@ app.listen(port, () => { The following example shows how to combine Prisma Client metrics with other Prometheus client libraries that are also served with a REST API endpoint in conjunction with `Express.js`: ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import express, { Request, Response } from 'express' import prom from 'prom-client' diff --git a/content/200-orm/200-prisma-client/600-observability-and-logging/250-opentelemetry-tracing.mdx b/content/200-orm/200-prisma-client/600-observability-and-logging/250-opentelemetry-tracing.mdx index f1b866c7d3..c3803e14ad 100644 --- a/content/200-orm/200-prisma-client/600-observability-and-logging/250-opentelemetry-tracing.mdx +++ b/content/200-orm/200-prisma-client/600-observability-and-logging/250-opentelemetry-tracing.mdx @@ -96,7 +96,8 @@ Tracing was added in version `4.2.0` of Prisma ORM as a Preview feature. For ver ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["tracing"] } ``` @@ -295,12 +296,12 @@ As an example, take the following Prisma schema: ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { @@ -468,7 +469,7 @@ registerTracing({ }) // You must import any dependencies after you register tracing. -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import async from 'express-async-handler' import express from 'express' ``` diff --git a/content/200-orm/200-prisma-client/700-debugging-and-troubleshooting/245-troubleshooting-binary-size-issues.mdx b/content/200-orm/200-prisma-client/700-debugging-and-troubleshooting/245-troubleshooting-binary-size-issues.mdx index 01ecf50d9b..9d65481b98 100644 --- a/content/200-orm/200-prisma-client/700-debugging-and-troubleshooting/245-troubleshooting-binary-size-issues.mdx +++ b/content/200-orm/200-prisma-client/700-debugging-and-troubleshooting/245-troubleshooting-binary-size-issues.mdx @@ -11,7 +11,8 @@ As of [v6.16.0](https://pris.ly/release/6.16.0), you can resolve these issues by ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" engineType = "client" } ```` diff --git a/content/200-orm/300-prisma-migrate/050-getting-started.mdx b/content/200-orm/300-prisma-migrate/050-getting-started.mdx index 20aa70d447..48f5ac3122 100644 --- a/content/200-orm/300-prisma-migrate/050-getting-started.mdx +++ b/content/200-orm/300-prisma-migrate/050-getting-started.mdx @@ -17,7 +17,6 @@ To get started with Prisma Migrate in a development environment: ```prisma file=schema.prisma showLineNumbers datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { diff --git a/content/200-orm/300-prisma-migrate/200-understanding-prisma-migrate/200-shadow-database.mdx b/content/200-orm/300-prisma-migrate/200-understanding-prisma-migrate/200-shadow-database.mdx index bfcec4db00..c07a407260 100644 --- a/content/200-orm/300-prisma-migrate/200-understanding-prisma-migrate/200-shadow-database.mdx +++ b/content/200-orm/300-prisma-migrate/200-understanding-prisma-migrate/200-shadow-database.mdx @@ -86,7 +86,6 @@ In some cases it might make sense (e.g. when [creating and dropping databases is ```prisma highlight=4;normal datasource db { provider = "postgresql" - url = env("DATABASE_URL") //highlight-next-line shadowDatabaseUrl = env("SHADOW_DATABASE_URL") } @@ -105,7 +104,6 @@ Some cloud providers do not allow you to drop and create databases with SQL. Som ```prisma highlight=4;normal datasource db { provider = "postgresql" - url = env("DATABASE_URL") //highlight-next-line shadowDatabaseUrl = env("SHADOW_DATABASE_URL") } diff --git a/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx b/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx index baf2358905..b59abd8ab6 100644 --- a/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx +++ b/content/200-orm/300-prisma-migrate/300-workflows/10-seeding.mdx @@ -100,7 +100,7 @@ Here we suggest some specific seed scripts for different situations. You are fre Create some new users and posts in your `seed.ts` file: ```js file=seed.ts - import { PrismaClient } from '@prisma/client' + import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() async function main() { const alice = await prisma.user.upsert({ @@ -198,12 +198,12 @@ Here we suggest some specific seed scripts for different situations. You are fre 2. In the `seed.js` file, import Prisma Client, initialize it and create some records. As an example, take the following Prisma schema with a `User` and `Post` model: ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { diff --git a/content/200-orm/300-prisma-migrate/300-workflows/110-native-database-types.mdx b/content/200-orm/300-prisma-migrate/300-workflows/110-native-database-types.mdx index ba21b41f1f..04f3e36898 100644 --- a/content/200-orm/300-prisma-migrate/300-workflows/110-native-database-types.mdx +++ b/content/200-orm/300-prisma-migrate/300-workflows/110-native-database-types.mdx @@ -43,7 +43,6 @@ In the following example, the `name` and `title` fields have a `@db.VarChar(X)` ```prisma highlight=8,14;normal datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { diff --git a/content/200-orm/300-prisma-migrate/300-workflows/120-native-database-functions.mdx b/content/200-orm/300-prisma-migrate/300-workflows/120-native-database-functions.mdx index 42cde2be6e..9ddcbd1028 100644 --- a/content/200-orm/300-prisma-migrate/300-workflows/120-native-database-functions.mdx +++ b/content/200-orm/300-prisma-migrate/300-workflows/120-native-database-functions.mdx @@ -20,14 +20,14 @@ In Prisma ORM versions 4.5.0 and later, you can activate the extension by declar ```prisma file=schema.prisma highlight=3,9;add showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" //add-next-line previewFeatures = ["postgresqlExtensions"] } datasource db { provider = "postgresql" - url = env("DATABASE_URL") //add-next-line extensions = [pgcrypto] } diff --git a/content/200-orm/300-prisma-migrate/300-workflows/20-prototyping-your-schema.mdx b/content/200-orm/300-prisma-migrate/300-workflows/20-prototyping-your-schema.mdx index 374f39309a..6e171e86c1 100644 --- a/content/200-orm/300-prisma-migrate/300-workflows/20-prototyping-your-schema.mdx +++ b/content/200-orm/300-prisma-migrate/300-workflows/20-prototyping-your-schema.mdx @@ -53,12 +53,12 @@ The following scenario demonstrates how to use `db push` to synchronize a new sc ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { @@ -176,12 +176,12 @@ The following scenario demonstrates how to use `db push` to prototype a change t ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { diff --git a/content/200-orm/500-reference/050-prisma-client-reference.mdx b/content/200-orm/500-reference/050-prisma-client-reference.mdx index cc31ef781c..89114f51ba 100644 --- a/content/200-orm/500-reference/050-prisma-client-reference.mdx +++ b/content/200-orm/500-reference/050-prisma-client-reference.mdx @@ -13,7 +13,8 @@ If Prisma ORM's Rust engine binaries cause large bundle sizes, slow builds, or d ```prisma generator client { - provider = "prisma-client-js" // or "prisma-client" + provider = "prisma-client" + output = "./generated" engineType = "client" } ``` @@ -106,7 +107,7 @@ From version 5.2.0 and upwards, you can also use the [`datasourceUrl`](#datasour ##### Programmatically override a datasource `url` ```ts -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; const prisma = new PrismaClient({ datasources: { @@ -122,7 +123,6 @@ Based on the following `datasource` block: ```prisma datasource db { provider = "sqlite" - url = env("DATABASE_URL") } ``` @@ -139,7 +139,7 @@ Programmatically overrides the [`datasource`](#datasources) block in the `schema #### Examples ```ts -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; const prisma = new PrismaClient({ datasourceUrl: 'postgresql://johndoe:randompassword@localhost:5432/mydb', @@ -208,7 +208,7 @@ export type LogEvent = { ```ts highlight=3;normal; -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; const prisma = new PrismaClient({ log: ['query', 'info'] }); @@ -247,7 +247,7 @@ prisma:query SELECT COUNT(*) FROM (SELECT "public"."User"."id" FROM "public"."Us ```ts -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; const prisma = new PrismaClient({ log: [{ level: 'query', emit: 'event' }], @@ -296,7 +296,7 @@ main() ```ts -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; const prisma = new PrismaClient({ log: [ @@ -415,7 +415,7 @@ The example below uses the [Neon driver adapter](/orm/overview/databases/neon#ho ```ts import { PrismaNeon } from '@prisma/adapter-neon'; -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; import dotenv from 'dotenv'; dotenv.config(); @@ -712,7 +712,7 @@ const user = await prisma.user.findFirst({ ##### Get the first `Post` record where the `title` starts with `A test`, reverse the list with `take` ```ts -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; const prisma = new PrismaClient({}); @@ -848,7 +848,7 @@ The following example results in **two** `INSERT` statements: ```ts -import { Prisma, PrismaClient } from '@prisma/client'; +import { Prisma, PrismaClient } from '../prisma/generated/client'; const prisma = new PrismaClient({ log: ['query'] }); @@ -2178,7 +2178,8 @@ Because the `relationLoadStrategy` option is currently in Preview, you need to e ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["relationJoins"] } ``` @@ -2954,10 +2955,12 @@ To enable `nativeDistinct`: ```prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["nativeDistinct"] } ``` +``` See [Preview Features](/orm/reference/preview-features/client-preview-features#preview-features-promoted-to-general-availability) for more details. @@ -5595,7 +5598,7 @@ Prisma.validator(PrismaClientInstance, '', '', ' The following example shows how you can extract and validate the input for the `create` operation you can reuse within your app: ```ts -import { Prisma } from '@prisma/client'; +import { Prisma } from '../prisma/generated/client'; const validateUserAndPostInput = (name, email, postTitle) => { return Prisma.validator()({ @@ -5613,7 +5616,7 @@ const validateUserAndPostInput = (name, email, postTitle) => { Here is an alternative syntax for the same operation: ```ts -import { Prisma } from '@prisma/client'; +import { Prisma } from '../prisma/generated/client'; import prisma from './prisma'; const validateUserAndPostInput = (name, email, postTitle) => { 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 ec555ae819..03f83a963f 100644 --- a/content/200-orm/500-reference/100-prisma-schema-reference.mdx +++ b/content/200-orm/500-reference/100-prisma-schema-reference.mdx @@ -78,7 +78,6 @@ In this example, the target database is available with the following credentials ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` @@ -2968,12 +2967,12 @@ The name of the `name` argument on the `@@schema` attribute can be omitted ```prisma highlight=3,9,16;normal generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") //highlight-next-line schemas = ["auth"] } @@ -2999,7 +2998,7 @@ For more information about using the `multiSchema` feature, refer to [this guide This features requires the `shardKeys` Preview feature flag on your `generator`: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../generated/prisma" previewFeatures = ["shardKeys"] } @@ -3022,7 +3021,7 @@ model User { This features requires the `shardKeys` Preview feature flag on your `generator`: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../generated/prisma" previewFeatures = ["shardKeys"] } diff --git a/content/200-orm/500-reference/200-prisma-cli-reference.mdx b/content/200-orm/500-reference/200-prisma-cli-reference.mdx index 8dd4fff307..c3900bfbbc 100644 --- a/content/200-orm/500-reference/200-prisma-cli-reference.mdx +++ b/content/200-orm/500-reference/200-prisma-cli-reference.mdx @@ -133,7 +133,7 @@ By default, the project sets up a [local Prisma Postgres](/postgres/database/loc | `--db` | No | Shorthand syntax for `--datasource-provider prisma+postgres`; creates a new [Prisma Postgres](/postgres) instance. Requires authentication in the [PDP Console](https://console.prisma.io). | | | `--prompt` (or `--vibe`) | No | Scaffolds a Prisma schema based on the prompt and deploys it to a fresh Prisma Postgres instance. Requires authentication in the [PDP Console](https://console.prisma.io). | | | `--url` | No | Define a custom `datasource` url. | | -| `--generator-provider` | No | Define the generator provider to use. | `prisma-client-js` | +| `--generator-provider` | No | Define the generator provider to use. | `prisma-client` | | `--preview-feature` | No | Define the [Preview features](/orm/reference/preview-features) to use. To define multiple Preview features, you have to provide the flag multiple times for each Preview feature. See examples. | | | `--output` | No | Specifies the [output location for the generated client](/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path). | `../generated/prisma` | | `--with-model` | No | Adds a simple `User` model to the initial Prisma schema. Available since version `5.14.0`. | | @@ -215,11 +215,11 @@ prisma init --preview-feature metrics ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["metrics"] } ``` @@ -243,11 +243,11 @@ prisma init --preview-feature view --preview-feature metrics ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["views", "metrics"] } ``` @@ -267,13 +267,12 @@ An initial `schema.prisma` file to define your schema in: // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { - provider = "prisma-client-js" + provider = "prisma-client" output = "../generated/prisma" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` @@ -323,11 +322,11 @@ A minimal `schema.prisma` file to define your schema in: datasource db { provider = "mysql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` @@ -350,19 +349,19 @@ DATABASE_URL="mysql://user:password@localhost:3306/mydb" The `generate` command generates assets like Prisma Client based on the [`generator`](/orm/prisma-schema/overview/generators) and [`data model`](/orm/prisma-schema/data-model/models) blocks defined in your `prisma/schema.prisma` file. -The `generate` command is most often used to generate Prisma Client with the `prisma-client-js` generator. This does three things: +The `generate` command is most often used to generate Prisma Client with the `prisma-client` generator. This does the following: -1. Searches the current directory and parent directories to find the applicable `npm` project. It will create a `package.json` file in the current directory if it cannot find one. -2. Installs the `@prisma/client` into the `npm` project if it is not already present. -3. Inspects the current directory to find a Prisma Schema to process. It will then generate a customized [Prisma Client](https://github.com/prisma/prisma-client-js) for your project. +1. Inspects the current directory to find a Prisma Schema to process. +2. Generates a customized Prisma Client based on your schema into the output directory specified in the generator block. #### Prerequisites -To use the `generate` command, you must add a generator definition in your `schema.prisma` file. The `prisma-client-js` generator, used to generate Prisma Client, can be added by including the following in your `schema.prisma` file: +To use the `generate` command, you must add a generator definition in your `schema.prisma` file. The `prisma-client` generator, used to generate Prisma Client, can be added by including the following in your `schema.prisma` file: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` @@ -413,7 +412,7 @@ prisma generate You can now start using Prisma Client in your code: -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' // or const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() @@ -469,7 +468,7 @@ prisma generate --generator client --generator zod_schemas #### Generated Assets -The `prisma-client-js` generator creates a customized client for working with your database within the `./node_modules/.prisma/client` directory by default - you can [customize the output folder](/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path). +The `prisma-client` generator creates a customized client for working with your database in a custom output directory specified by the `output` field - you can [customize the output folder](/orm/prisma-client/setup-and-configuration/generating-prisma-client#using-a-custom-output-path). ### `validate` @@ -524,7 +523,7 @@ Error code: P1012 error: The preview feature "unknownFeatureFlag" is not known. Expected one of: [...] --> schema.prisma:3 | - 2 | provider = "prisma-client-js" + 2 | provider = "prisma-client" 3 | previewFeatures = ["unknownFeatureFlag"] | @@ -591,7 +590,7 @@ Error code: P1012 error: The preview feature "unknownFeatureFlag" is not known. Expected one of: [...] --> schema.prisma:3 | - 2 | provider = "prisma-client-js" + 2 | provider = "prisma-client" 3 | previewFeatures = ["unknownFeatureFlag"] | @@ -923,7 +922,8 @@ prisma db pull --print ```prisma no-copy generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { diff --git a/content/200-orm/500-reference/380-connection-urls.mdx b/content/200-orm/500-reference/380-connection-urls.mdx index 68fd631f08..99cd1a334f 100644 --- a/content/200-orm/500-reference/380-connection-urls.mdx +++ b/content/200-orm/500-reference/380-connection-urls.mdx @@ -156,7 +156,6 @@ You can also provide the connection URL as an environment variable: ```prisma file=schema.prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` 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 1ea24923c5..f4f60abfc8 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 @@ -33,7 +33,8 @@ To enable a Prisma Client Preview feature: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["relationJoins"] } ``` diff --git a/content/200-orm/800-more/100-under-the-hood/100-engines.mdx b/content/200-orm/800-more/100-under-the-hood/100-engines.mdx index 78a8e65d4e..8e8d86420b 100644 --- a/content/200-orm/800-more/100-under-the-hood/100-engines.mdx +++ b/content/200-orm/800-more/100-under-the-hood/100-engines.mdx @@ -22,7 +22,7 @@ As of [v6.16.0](https://pris.ly/release/6.16.0), Prisma ORM can be used without ```prisma generator client { - provider = "prisma-client-js" // or "prisma-client" + provider = "prisma-client" output = "../src/generated/prisma" engineType = "client" // no Rust engine } @@ -235,7 +235,8 @@ Learn more about [Debugging](/orm/prisma-client/debugging-and-troubleshooting/de ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" engineType = "binary" } ``` diff --git a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/500-upgrading-to-prisma-6.mdx b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/500-upgrading-to-prisma-6.mdx index 180853f6d7..a166e86f16 100644 --- a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/500-upgrading-to-prisma-6.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/500-upgrading-to-prisma-6.mdx @@ -190,11 +190,11 @@ The [`fullTextSearch`](/orm/prisma-client/queries/full-text-search) Preview feat ```prisma file=schema.prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" // edit-next-line previewFeatures = ["fullTextSearch"] } @@ -205,11 +205,11 @@ generator client { ```prisma file=schema.prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" // edit-next-line previewFeatures = ["fullTextSearchPostgres"] } @@ -250,7 +250,7 @@ const buffer: Buffer = Buffer.from(uint8Array.buffer); ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' async function main() { const prisma = new PrismaClient() @@ -295,7 +295,7 @@ model User { ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' async function main() { const prisma = new PrismaClient() @@ -342,7 +342,7 @@ In Prisma v6, we removed the `NotFoundError` in favor of `PrismaClientKnownReque #### Before ```ts -import { PrismaClient, NotFoundError } from '@prisma/client'; +import { PrismaClient, NotFoundError } from '../prisma/generated/client'; // inside an `async` function try { @@ -365,7 +365,7 @@ try { #### After ```ts -import { PrismaClient, Prisma } from '@prisma/client'; +import { PrismaClient, Prisma } from '../prisma/generated/client'; // inside an `async` function try { @@ -403,7 +403,8 @@ If you use the [full-text index](/orm/prisma-schema/data-model/indexes#full-text ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" // delete-next-line previewFeatures = ["fullTextIndex"] } @@ -415,7 +416,8 @@ If you use the [full-text search](/orm/prisma-client/queries/full-text-search) f ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" // delete-next-line previewFeatures = ["fullTextSearch"] } @@ -425,7 +427,8 @@ If you are using it with **PostgreSQL**, you need to update the name of the feat ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" // edit-next-line previewFeatures = ["fullTextSearchPostgres"] } diff --git a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/001-rejectonnotfound-changes.mdx b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/001-rejectonnotfound-changes.mdx index 033877a9bc..7351d7171b 100644 --- a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/001-rejectonnotfound-changes.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/001-rejectonnotfound-changes.mdx @@ -141,7 +141,7 @@ You will need to update your method usage to `...OrThrow` and then use a [Client As an example, the following extension would give the same behavior in Prisma ORM 5 that `Example 5` gave in Prisma ORM 4 and lower. ```js -import { PrismaClient } from '@prisma/client'; +import { PrismaClient } from '../prisma/generated/client'; const customErrorFunc = async (model, query, args) => { try { diff --git a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/101-jsonprotocol-changes.mdx b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/101-jsonprotocol-changes.mdx index 9b21076af3..c20537a7a9 100644 --- a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/101-jsonprotocol-changes.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/101-jsonprotocol-changes.mdx @@ -26,7 +26,8 @@ Prisma ORM 4 and lower: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["jsonProtocol"] } ``` @@ -35,7 +36,8 @@ Prisma ORM 5: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` diff --git a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/index.mdx b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/index.mdx index 637b4c4e4b..a56e3e79aa 100644 --- a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/index.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/600-upgrading-to-prisma-5/index.mdx @@ -102,7 +102,8 @@ Prisma ORM 4 and lower: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" previewFeatures = ["jsonProtocol"] } ``` @@ -111,7 +112,8 @@ Prisma ORM 5: ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` @@ -156,7 +158,7 @@ The `runtime/index.js` file has been removed from Prisma Client. Importing from `@prisma/client/runtime` is no longer available in Prisma ORM 5. If you were using public APIs available in this namespace before, you can instead import `Prisma` and access them. For example: ```js -import { Decimal, NotFoundError } from '@prisma/client/runtime' +import { Decimal, NotFoundError } from '../prisma/generated/client/runtime' const num = new Decimal(24.454545) const notFound = new NotFoundError() ``` @@ -164,7 +166,7 @@ const notFound = new NotFoundError() will need to be changed to ```js -import { Prisma } from '@prisma/client' +import { Prisma } from '../prisma/generated/client' const num = new Prisma.Decimal(24.454545) const notFound = new Prisma.NotFoundError() ``` diff --git a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/150-referential-actions.mdx b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/150-referential-actions.mdx index a099b97d22..0eb4d3ec87 100644 --- a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/150-referential-actions.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/150-referential-actions.mdx @@ -135,7 +135,7 @@ Prior to upgrading, the error code you would receive when trying to delete a use > "The change you are trying to make would violate the required relation '\{relation_name}' between the \{model_a_name} and \{model_b_name} models." ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() @@ -171,7 +171,7 @@ To make sure you are checking for the correct errors in your code, modify your c > "Foreign key constraint failed on the field: \{field_name}" ```ts highlight=14;delete|15;add -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() diff --git a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/index.mdx b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/index.mdx index 2180704600..33cdf17fb2 100644 --- a/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/index.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/200-upgrading-versions/800-upgrading-to-prisma-3/index.mdx @@ -78,7 +78,7 @@ prisma.log.findMany({ To fix this, you'll import and use one of the new null types: ```ts highlight=7;normal -import { Prisma } from '@prisma/client' +import { Prisma } from '../prisma/generated/client' prisma.log.findMany({ where: { @@ -95,7 +95,7 @@ This also applies to `create`, `update` and `upsert`. To insert a `null` value into a `Json` field, you would write: ```ts highlight=5;normal -import { Prisma } from '@prisma/client' +import { Prisma } from '../prisma/generated/client' prisma.log.create({ data: { @@ -107,7 +107,7 @@ prisma.log.create({ And to insert a database `NULL` into a Json field, you would write: ```ts highlight=5;normal -import { Prisma } from '@prisma/client' +import { Prisma } from '../prisma/generated/client' prisma.log.create({ data: { diff --git a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-mysql.mdx b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-mysql.mdx index 2adb0deb6c..1aebcd25bf 100644 --- a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-mysql.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-mysql.mdx @@ -148,11 +148,11 @@ Your initial Prisma schema looks as follows: datasource db { provider = "mysql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` @@ -181,7 +181,6 @@ Switch around with the tabs in the code block to see examples of both: ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` @@ -191,7 +190,6 @@ datasource db { ```prisma datasource db { provider = "mysql" - url = env("DATABASE_URL") } ``` diff --git a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-postgresql.mdx b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-postgresql.mdx index eb250661e0..1d23bf820b 100644 --- a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-postgresql.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/03-upgrading-the-prisma-layer-postgresql.mdx @@ -156,11 +156,11 @@ Your initial Prisma schema looks as follows: datasource db { provider = "postgresql" - url = env("DATABASE_URL") } generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` @@ -189,7 +189,6 @@ Switch around with the tabs in the code block to see examples of both: ```prisma datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` @@ -199,7 +198,6 @@ datasource db { ```prisma datasource db { provider = "mysql" - url = env("DATABASE_URL") } ``` diff --git a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/04-upgrading-nexus-prisma-to-nexus.mdx b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/04-upgrading-nexus-prisma-to-nexus.mdx index 0fbcc232cb..d8d9aa7af2 100644 --- a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/04-upgrading-nexus-prisma-to-nexus.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/04-upgrading-nexus-prisma-to-nexus.mdx @@ -103,7 +103,7 @@ Instead, you now import the following into your application: //add-start import { nexusSchemaPrisma } from 'nexus-plugin-prisma/schema' import { objectType, makeSchema, queryType, mutationType } from '@nexus/schema' -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' //add-end ``` @@ -164,7 +164,7 @@ If you previously typed the GraphQL `context` object that's passed through your //delete-next-line import { Prisma } from './generated/prisma-client' //add-next-line -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' export interface Context { //delete-next-line diff --git a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/05-upgrading-prisma-binding-to-nexus.mdx b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/05-upgrading-prisma-binding-to-nexus.mdx index 3110ebafdc..138d948ab4 100644 --- a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/05-upgrading-prisma-binding-to-nexus.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/05-upgrading-prisma-binding-to-nexus.mdx @@ -171,7 +171,7 @@ touch src/context.ts Now add the following code to it: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() diff --git a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/06-upgrading-prisma-binding-to-sdl-first.mdx b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/06-upgrading-prisma-binding-to-sdl-first.mdx index fcca75b411..a3e70fa7bd 100644 --- a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/06-upgrading-prisma-binding-to-sdl-first.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/06-upgrading-prisma-binding-to-sdl-first.mdx @@ -773,7 +773,7 @@ The `PrismaClient` query API is inspired by the initial `prisma-binding` API, so Similar to the `prisma-binding` instance from Prisma 1, you also want to attach your `PrismaClient` from Prisma ORM 2 to GraphQL's `context` so that in can be accessed inside your resolvers: ```js line-number highlight=10-13;delete|14;add -const { PrismaClient } = require('@prisma/client') +const { PrismaClient } = require('../prisma/generated/client') // ... diff --git a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/07-upgrading-a-rest-api.mdx b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/07-upgrading-a-rest-api.mdx index 2db3af392f..ca8d749730 100644 --- a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/07-upgrading-a-rest-api.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/07-upgrading-a-rest-api.mdx @@ -131,7 +131,7 @@ Consider each occurrence of the Prisma Client instance `prisma` and replacing wi Import the generated `@prisma/client` node module as shown: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' ``` Note that this only imports the `PrismaClient` constructor, so you also need to instantiate a Prisma Client 2 instance: diff --git a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/08-upgrade-from-mongodb-beta.mdx b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/08-upgrade-from-mongodb-beta.mdx index 4358dc8ae2..4964f8bb76 100644 --- a/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/08-upgrade-from-mongodb-beta.mdx +++ b/content/200-orm/800-more/300-upgrade-guides/800-upgrade-from-prisma-1/08-upgrade-from-mongodb-beta.mdx @@ -131,7 +131,7 @@ $ npx prisma generate Create a simple `test.ts` script to verify that Prisma Client can read and write to your application. Note that this guide is using the example in the [Prisma 1 examples repository](https://github.com/prisma/prisma1-examples/tree/master/typescript/docker-mongodb), but the code will change depending on your application. ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() async function main() { @@ -190,7 +190,7 @@ You should see a list of your data: You can then alter your `test.ts` to try writes: ```ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() async function main() { diff --git a/content/200-orm/800-more/350-ai-tools/100-cursor.mdx b/content/200-orm/800-more/350-ai-tools/100-cursor.mdx index 2ab60d89ab..97b1b6fbb5 100644 --- a/content/200-orm/800-more/350-ai-tools/100-cursor.mdx +++ b/content/200-orm/800-more/350-ai-tools/100-cursor.mdx @@ -206,12 +206,12 @@ If you run the prompts below, you may receive a different outputs because LLMs p ```prisma file=schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } @@ -341,7 +341,7 @@ import { UserRole, SubscriptionPlan, SubscriptionStatus, -} from "@prisma/client"; +} from "../prisma/generated/client"; const prisma = new PrismaClient(); diff --git a/content/200-orm/800-more/350-ai-tools/200-tabnine.mdx b/content/200-orm/800-more/350-ai-tools/200-tabnine.mdx index 63c470a872..c67ad37b70 100644 --- a/content/200-orm/800-more/350-ai-tools/200-tabnine.mdx +++ b/content/200-orm/800-more/350-ai-tools/200-tabnine.mdx @@ -56,12 +56,12 @@ _Define a Prisma schema for a SaaS application with User, Organization, and Subs ```prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { @@ -316,8 +316,8 @@ GROUP BY status; #### Application code ```ts -import { PrismaClient } from '@prisma/client' -import { subscriptionsReport } from '@prisma/client/sql' +import { PrismaClient } from '../prisma/generated/client' +import { subscriptionsReport } from '../prisma/generated/client/sql' const prisma = new PrismaClient(); @@ -416,7 +416,7 @@ _Generate a Prisma seed script for populating User, Organization, and Subscripti #### Generated code ```ts -import { PrismaClient } from "@prisma/client"; +import { PrismaClient } from "../prisma/generated/client"; const prisma = new PrismaClient(); diff --git a/content/200-orm/800-more/350-ai-tools/300-windsurf.mdx b/content/200-orm/800-more/350-ai-tools/300-windsurf.mdx index 814c77f782..35aacddc1d 100644 --- a/content/200-orm/800-more/350-ai-tools/300-windsurf.mdx +++ b/content/200-orm/800-more/350-ai-tools/300-windsurf.mdx @@ -233,12 +233,12 @@ LLMs may produce different results each time, even with the same prompt. ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { @@ -365,7 +365,7 @@ import { UserRole, SubscriptionPlan, SubscriptionStatus, -} from "@prisma/client"; +} from "../prisma/generated/client"; const prisma = new PrismaClient(); diff --git a/content/200-orm/800-more/350-ai-tools/400-github-copilot.mdx b/content/200-orm/800-more/350-ai-tools/400-github-copilot.mdx index 740f3b9305..ea70d9b59e 100644 --- a/content/200-orm/800-more/350-ai-tools/400-github-copilot.mdx +++ b/content/200-orm/800-more/350-ai-tools/400-github-copilot.mdx @@ -137,7 +137,7 @@ You can tailor Copilot Chat's behavior in your repository by [adding a `.github/ ```ts // prisma.ts - import { PrismaClient } from '@prisma/client'; + import { PrismaClient } from '../prisma/generated/client'; export const prisma = global.prisma || new PrismaClient(); if (process.env.NODE_ENV !== 'production') global.prisma = prisma; /``` diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/100-autocompletion-in-graphql-resolvers-with-js.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/100-autocompletion-in-graphql-resolvers-with-js.mdx index 912ecb7d92..963f8db2eb 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/100-autocompletion-in-graphql-resolvers-with-js.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/100-autocompletion-in-graphql-resolvers-with-js.mdx @@ -39,7 +39,7 @@ To overcome this, you need to add a [JSDoc](https://jsdoc.app/) comment named `t // Add this to the top of the file /** - * @typedef { import("@prisma/client").PrismaClient } Prisma + * @typedef { import("../prisma/generated/client").PrismaClient } Prisma */ ``` @@ -75,8 +75,8 @@ The final file should look something like: ```js /** - * @typedef { import("@prisma/client").PrismaClient } Prisma - * @typedef { import("@prisma/client").UserCreateArgs } UserCreateArgs + * @typedef { import("../prisma/generated/client").PrismaClient } Prisma + * @typedef { import("../prisma/generated/client").UserCreateArgs } UserCreateArgs */ const { makeExecutableSchema } = require('graphql-tools') diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/300-implicit-to-explicit-conversion.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/300-implicit-to-explicit-conversion.mdx index b65c07c74f..fcdc3a5c1b 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/300-implicit-to-explicit-conversion.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/300-implicit-to-explicit-conversion.mdx @@ -76,7 +76,7 @@ To migrate the existing data from the implicit relation table to the new explici Considering the above `User` and `Post` models, here’s an example script you can use to migrate data. ```typescript -import { PrismaClient } from "@prisma/client"; +import { PrismaClient } from "../prisma/generated/client"; const prisma = new PrismaClient(); diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/400-nextjs-help.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/400-nextjs-help.mdx index 075f318eb0..19dc9c0bfc 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/400-nextjs-help.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/400-nextjs-help.mdx @@ -31,7 +31,7 @@ To avoid this, create a single Prisma Client instance by using a global variable ```typescript // lib/prisma.ts -import { PrismaClient } from "@prisma/client"; +import { PrismaClient } from "../prisma/generated/client"; const globalForPrisma = global as unknown as { prisma: PrismaClient }; @@ -91,7 +91,7 @@ Use a factory function to dynamically create Prisma Clients based on tenant-spec ```typescript // lib/prismaDynamic.ts -import { PrismaClient } from "@prisma/client"; +import { PrismaClient } from "../prisma/generated/client"; type TenantConfig = { databaseUrl: string; diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/500-comparing-columns-through-raw-queries.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/500-comparing-columns-through-raw-queries.mdx index 146867f787..4927d97346 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/500-comparing-columns-through-raw-queries.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/500-comparing-columns-through-raw-queries.mdx @@ -48,7 +48,7 @@ Queries (depending upon which database) could look something like: _PostgreSQL / CockroachDB_ ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() @@ -65,7 +65,7 @@ await initiateNumbersComparisonRawQuery() _MySQL_ ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() @@ -82,7 +82,7 @@ await initiateNumbersComparisonRawQuery() _Sqlite_ ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() @@ -145,7 +145,7 @@ Queries (depending upon the database) could look something like: _PostgreSQL / CockroachDB_ ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() @@ -162,7 +162,7 @@ await initiateDatesComparisonRawQuery() _MySQL_ ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() @@ -179,7 +179,7 @@ await initiateDatesComparisonRawQuery() _Sqlite_ ```js -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prisma = new PrismaClient() diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/800-check-constraints.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/800-check-constraints.mdx index 2166927bc6..a4dc7b9815 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/800-check-constraints.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/800-check-constraints.mdx @@ -260,7 +260,6 @@ Create a new file named `schema.prisma` and add the following code to it: ```prisma file=schema.prisma showLineNumbers datasource db { provider = "postgresql" - url = env("DATABASE_URL") } ``` @@ -288,12 +287,12 @@ This command introspects your database and for each table adds a Prisma model to ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model anotherproduct { @@ -328,7 +327,8 @@ First, add a `generator` block to your Prisma schema (typically added right belo ```prisma file=schema.prisma showLineNumbers generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` @@ -345,7 +345,7 @@ Now you can use Prisma Client to send database queries in Node.js. Create a new file named `index.js` and add the following code to it: ```js -const { PrismaClient } = require('@prisma/client') +const { PrismaClient } = require('../prisma/generated/client') const prisma = new PrismaClient() @@ -380,7 +380,7 @@ ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error To validate the multi-column check constraint, replace the code in `index.js` with the following: ```js -const { PrismaClient } = require('@prisma/client') +const { PrismaClient } = require('../prisma/generated/client') const prisma = new PrismaClient() @@ -416,7 +416,7 @@ ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Error Finally, modify the script to include multiple check constraint violations: ```js -const { PrismaClient } = require('@prisma/client') +const { PrismaClient } = require('../prisma/generated/client') const prisma = new PrismaClient() diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/900-prisma-nuxt-module.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/900-prisma-nuxt-module.mdx index b6fa843888..1821dd4f7f 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/900-prisma-nuxt-module.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/900-prisma-nuxt-module.mdx @@ -51,12 +51,12 @@ This module provides several features to streamline the setup and usage of Prism // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "sqlite" - url = env("DATABASE_URL") } model User { @@ -103,12 +103,12 @@ To configure [the getting started example](#getting-started) to use a PostgreSQL // learn more about it in the docs: https://pris.ly/d/prisma-schema generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") } model User { @@ -190,7 +190,7 @@ If you're using [Nuxt server components](https://nuxt.com/docs/guide/directory-s After running through the initial setup prompts, this module creates the `lib/prisma.ts` file which contains a global instance of Prisma Client. ```typescript file=lib/prisma.ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const prismaClientSingleton = () => { return new PrismaClient() @@ -210,7 +210,7 @@ if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma You can customize Prisma Client's capabilities by using client extensions in your `lib/prisma.ts` file. Here is an example using the [Accelerate client extension](https://www.npmjs.com/package/@prisma/extension-accelerate): ```typescript file=lib/prisma.ts -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' import { withAccelerate } from '@prisma/extension-accelerate' const prismaClientSingleton = () => { @@ -366,7 +366,8 @@ Please try delete `output = ../generated/prisma` in schema.prisma, like ```prisma file=prisma/schema.prisma generator client { - provider = "prisma-client-js" + provider = "prisma-client" + output = "./generated" } ``` diff --git a/content/200-orm/800-more/600-help-and-troubleshooting/950-typescript-performance-optimization.mdx b/content/200-orm/800-more/600-help-and-troubleshooting/950-typescript-performance-optimization.mdx index 4cd6f46770..ba4de7c29e 100644 --- a/content/200-orm/800-more/600-help-and-troubleshooting/950-typescript-performance-optimization.mdx +++ b/content/200-orm/800-more/600-help-and-troubleshooting/950-typescript-performance-optimization.mdx @@ -70,7 +70,7 @@ The solution involves using TypeScript's `typeof` operator instead of direct typ ### Problematic approach for large schemas ```typescript -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const saveFn = async (prismaClient: PrismaClient) => { // Function implementation @@ -89,7 +89,7 @@ await saveFn(client) ### Optimized approach with `typeof` ```typescript -import { PrismaClient } from '@prisma/client' +import { PrismaClient } from '../prisma/generated/client' const saveFn = async (prismaClient: typeof client) => { // Function implementation diff --git a/package-lock.json b/package-lock.json index b57e49bc85..0238c50194 100644 --- a/package-lock.json +++ b/package-lock.json @@ -247,6 +247,7 @@ "resolved": "https://registry.npmjs.org/@algolia/client-search/-/client-search-5.40.0.tgz", "integrity": "sha512-nlr/MMgoLNUHcfWC5Ns2ENrzKx9x51orPc6wJ8Ignv1DsrUmKm0LUih+Tj3J+kxYofzqQIQRU495d4xn3ozMbg==", "license": "MIT", + "peer": true, "dependencies": { "@algolia/client-common": "5.40.0", "@algolia/requester-browser-xhr": "5.40.0", @@ -372,6 +373,7 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.4.tgz", "integrity": "sha512-2BCOP7TN8M+gVDj7/ht3hsaO/B/n5oDbiAyyvnRlNOs+u1o+JWNYTQrmpuNp1/Wq2gcFrI01JAW+paEKDMx/CA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.3", @@ -2312,6 +2314,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=18" }, @@ -2334,6 +2337,7 @@ } ], "license": "MIT", + "peer": true, "engines": { "node": ">=18" } @@ -2443,6 +2447,7 @@ "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.0.tgz", "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "license": "MIT", + "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -2864,6 +2869,7 @@ "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.0.tgz", "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "license": "MIT", + "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -3546,6 +3552,7 @@ "resolved": "https://registry.npmjs.org/@docusaurus/core/-/core-3.9.1.tgz", "integrity": "sha512-FWDk1LIGD5UR5Zmm9rCrXRoxZUgbwuP6FBA7rc50DVfzqDOMkeMe3NyJhOsA2dF0zBE3VbHEIMmTjKwTZJwbaA==", "license": "MIT", + "peer": true, "dependencies": { "@docusaurus/babel": "3.9.1", "@docusaurus/bundler": "3.9.1", @@ -3622,6 +3629,7 @@ "resolved": "https://registry.npmjs.org/@docusaurus/faster/-/faster-3.9.1.tgz", "integrity": "sha512-zJIrIv+R/IN5TTLV9L+SvO3hwz62L6pO/L16k+b2nC3to3Gn01cnEGHL6doTGAezuPwTSmteJl+kzaoOf+znzg==", "license": "MIT", + "peer": true, "dependencies": { "@docusaurus/types": "3.9.1", "@rspack/core": "^1.5.0", @@ -3750,6 +3758,7 @@ "resolved": "https://registry.npmjs.org/@docusaurus/plugin-content-docs/-/plugin-content-docs-3.9.1.tgz", "integrity": "sha512-DyLk9BIA6I9gPIuia8XIL+XIEbNnExam6AHzRsfrEq4zJr7k/DsWW7oi4aJMepDnL7jMRhpVcdsCxdjb0/A9xg==", "license": "MIT", + "peer": true, "dependencies": { "@docusaurus/core": "3.9.1", "@docusaurus/logger": "3.9.1", @@ -5530,6 +5539,7 @@ "resolved": "https://registry.npmjs.org/@mdx-js/react/-/react-3.1.1.tgz", "integrity": "sha512-f++rKLQgUVYDAtECQ6fn/is15GkEH9+nZPM3MS0RcxVqoTfawHvDlSCH7JbMhAM6uJ32v3eXLvLmLvjGu7PTQw==", "license": "MIT", + "peer": true, "dependencies": { "@types/mdx": "^2.0.0" }, @@ -6712,6 +6722,7 @@ "resolved": "https://registry.npmjs.org/@svgr/core/-/core-8.1.0.tgz", "integrity": "sha512-8QqtOQT5ACVlmsvKOJNEaWmRPmcojMOzCz4Hs2BGG/toAp/K38LcsMRyLp349glq5AzJbCEeimEoxaX6v/fLrA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/core": "^7.21.3", "@svgr/babel-preset": "8.1.0", @@ -6816,6 +6827,7 @@ "integrity": "sha512-WezcBo8a0Dg2rnR82zhwoR6aRNxeTGfK5QCD6TQ+kg3xx/zNT02s/0o+81h/3zhvFSB24NtqEr8FTw88O5W/JQ==", "hasInstallScript": true, "license": "Apache-2.0", + "peer": true, "dependencies": { "@swc/counter": "^0.1.3", "@swc/types": "^0.1.24" @@ -7505,6 +7517,7 @@ "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.2.tgz", "integrity": "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==", "license": "MIT", + "peer": true, "dependencies": { "csstype": "^3.0.2" } @@ -7864,6 +7877,7 @@ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz", "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -7949,6 +7963,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -7994,6 +8009,7 @@ "resolved": "https://registry.npmjs.org/algoliasearch/-/algoliasearch-5.40.0.tgz", "integrity": "sha512-a9aIL2E3Z7uYUPMCmjMFFd5MWhn+ccTubEvnMy7rOTZCB62dXBJtz0R5BZ/TPuX3R9ocBsgWuAbGWQ+Ph4Fmlg==", "license": "MIT", + "peer": true, "dependencies": { "@algolia/abtesting": "1.6.0", "@algolia/client-abtesting": "5.40.0", @@ -8505,6 +8521,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.9", "caniuse-lite": "^1.0.30001746", @@ -9537,6 +9554,7 @@ "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.0.tgz", "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "license": "MIT", + "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -11105,6 +11123,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -16152,6 +16171,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -16832,6 +16852,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -17735,6 +17756,7 @@ "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-7.1.0.tgz", "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "license": "MIT", + "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -18571,6 +18593,7 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.2.0.tgz", "integrity": "sha512-tmbWg6W31tQLeB5cdIBOicJDJRR2KzXsV7uSK9iNfLWQ5bIZfxuPEHp7M8wiHyHnn0DD1i7w3Zmin0FtkrwoCQ==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -18580,6 +18603,7 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.0.tgz", "integrity": "sha512-UlbRu4cAiGaIewkPyiRGJk0imDN2T3JjieT6spoL2UeSf5od4n5LB/mQ4ejmxhCFT1tYe8IvaFulzynWovsEFQ==", "license": "MIT", + "peer": true, "dependencies": { "scheduler": "^0.27.0" }, @@ -18635,6 +18659,7 @@ "resolved": "https://registry.npmjs.org/@docusaurus/react-loadable/-/react-loadable-6.0.0.tgz", "integrity": "sha512-YMMxTUQV/QFSnbgrP3tjDzLHRg7vsbMn8e9HAa8o/1iXoiomo48b7sk/kkmWEuWNDPJVlKSJRB6Y2fHqdJk+SQ==", "license": "MIT", + "peer": true, "dependencies": { "@types/react": "*" }, @@ -18663,6 +18688,7 @@ "resolved": "https://registry.npmjs.org/react-router/-/react-router-5.3.4.tgz", "integrity": "sha512-Ys9K+ppnJah3QuaRiLxk+jDWOR1MekYQrlytiXxC1RyfbdsZkS5pvKAzCCr031xHixZwpnsYNT5xysdFHQaYsA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/runtime": "^7.12.13", "history": "^4.9.0", @@ -19414,6 +19440,7 @@ "resolved": "https://registry.npmjs.org/sass/-/sass-1.93.2.tgz", "integrity": "sha512-t+YPtOQHpGW1QWsh1CHQ5cPIr9lbbGZLZnbihP/D/qZj/yuV68m8qarcV17nvkOX81BCrvzAlq2klCQFZghyTg==", "license": "MIT", + "peer": true, "dependencies": { "chokidar": "^4.0.0", "immutable": "^5.0.2", @@ -20716,7 +20743,8 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD" + "license": "0BSD", + "peer": true }, "node_modules/type-fest": { "version": "2.19.0", @@ -20779,6 +20807,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "devOptional": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -20815,6 +20844,7 @@ "integrity": "sha512-Wj7/AMtE9MRnAXa6Su3Lk0LNCfqDYgfwVjwRFVum9U7wsto1imuHqk4kTm7Jni+5A0Hn7dttL6O/zjvUvoo+8A==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "defu": "^6.1.4", "exsolve": "^1.0.7", @@ -21180,6 +21210,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "license": "MIT", + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -21401,6 +21432,7 @@ "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.102.1.tgz", "integrity": "sha512-7h/weGm9d/ywQ6qzJ+Xy+r9n/3qgp/thalBbpOi5i223dPXKi04IBtqPN9nTd+jBc7QKfvDbaBnFipYp4sJAUQ==", "license": "MIT", + "peer": true, "dependencies": { "@types/eslint-scope": "^3.7.7", "@types/estree": "^1.0.8", @@ -21828,6 +21860,7 @@ "dev": true, "hasInstallScript": true, "license": "Apache-2.0", + "peer": true, "bin": { "workerd": "bin/workerd" }, @@ -22094,6 +22127,7 @@ "resolved": "https://registry.npmjs.org/zod/-/zod-4.1.12.tgz", "integrity": "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ==", "license": "MIT", + "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } From 5a87e30cac2d9dcc29bd32031433f26e8174c64d Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Sat, 15 Nov 2025 17:40:49 +0530 Subject: [PATCH 2/2] use pg adapter instead of accelerate --- .../301-edge/550-deploy-to-deno-deploy.mdx | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx b/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx index d47dfa0c7c..88c15dfb4c 100644 --- a/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx +++ b/content/200-orm/200-prisma-client/500-deployment/301-edge/550-deploy-to-deno-deploy.mdx @@ -10,12 +10,6 @@ With this guide, you can learn how to build and deploy a simple application to [ This guide covers the use of Prisma CLI with Deno CLI, Deno Deploy, Prisma Client, and Prisma Postgres. -:::info - -This guide demonstrates how to deploy an application to Deno Deploy with a Prisma Postgres database, but you can also use [your own database with Prisma Accelerate](/accelerate/getting-started#prerequisites). - -::: - :::tip Use Prisma ORM without Rust binaries If Prisma ORM's Rust engine binaries cause large bundle sizes, slow builds, or deployment issues (for example, in serverless or edge environments), you can use it without them using this configuration of your `generator` block: @@ -70,7 +64,7 @@ This command: - Connects your CLI to your [Prisma Data Platform](https://console.prisma.io) account. If you're not logged in or don't have an account, your browser will open to guide you through creating a new account or signing into your existing one. - Creates a `prisma` directory containing a `schema.prisma` file for your database models. -- Creates a `.env` file with your `DATABASE_URL` (e.g., for Prisma Postgres it should have something similar to `DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI..."`). +- Creates a `.env` file with your `DATABASE_URL` (e.g., `DATABASE_URL="postgresql://user:password@host:5432/database"`). Edit the `prisma/schema.prisma` file to define a `Log` model, add a custom `output` path and [the `prisma-client` generator](/orm/prisma-schema/overview/generators#prisma-client) with `deno` as the `runtime`: @@ -106,16 +100,11 @@ enum Level { //add-end ``` -Then, install Prisma Client: +Then, install Prisma Client and the Postgres adapter: ```terminal deno install npm:@prisma/client -``` - -Then, install [the Client extension](https://www.npmjs.com/package/@prisma/extension-accelerate) required to use Prisma Postgres: - -```terminal -deno install npm:@prisma/extension-accelerate +deno install npm:@prisma/adapter-pg ``` Prisma Client does not read `.env` files by default on Deno, so you must also install `dotenv-cli` locally: @@ -145,10 +134,12 @@ You can now create a local Deno application. Create `index.ts` in the root folde ```ts file=index.ts import { serve } from "https://deno.land/std@0.140.0/http/server.ts"; -import { withAccelerate } from "npm:@prisma/extension-accelerate"; +import { PrismaPg } from "npm:@prisma/adapter-pg"; import { PrismaClient } from "../generated/prisma/client.ts"; -const prisma = new PrismaClient().$extends(withAccelerate()); +const connectionString = `${Deno.env.get("DATABASE_URL")}`; +const adapter = new PrismaPg({ connectionString }); +const prisma = new PrismaClient({ adapter }); async function handler(request: Request) { // Ignore /favicon.ico requests: @@ -252,10 +243,12 @@ Add the following code in your `index.ts` file: ```ts file=index.ts import { serve } from "https://deno.land/std@0.140.0/http/server.ts"; -import { withAccelerate } from "npm:@prisma/extension-accelerate"; +import { PrismaPg } from "npm:@prisma/adapter-pg"; import { PrismaClient } from "../generated/prisma/client.ts"; -const prisma = new PrismaClient().$extends(withAccelerate()); +const connectionString = `${Deno.env.get("DATABASE_URL")}`; +const adapter = new PrismaPg({ connectionString }); +const prisma = new PrismaClient({ adapter }); async function handler(request: Request) { // Ignore /favicon.ico requests: @@ -309,4 +302,4 @@ This rebuilds the deployment, which now works because the environment variable h ## Summary -You successfully deployed a Deno application that you created in TypeScript, which uses Prisma Client connecting to a Prisma Postgres database. +You successfully deployed a Deno application that you created in TypeScript, which uses Prisma Client with the Postgres adapter to connect to a Postgres database.