diff --git a/content/200-concepts/100-components/drivers.mdx b/content/200-concepts/100-components/drivers.mdx index 672afc8d75..f02daac410 100644 --- a/content/200-concepts/100-components/drivers.mdx +++ b/content/200-concepts/100-components/drivers.mdx @@ -2,7 +2,6 @@ title: 'Drivers' metaTitle: 'Drivers' metaDescription: 'Learn how Prisma connects to your database using the built-in drivers and how you can use Prisma along with other JavaScript database drivers using driver adapters (Preview)' -preview: true tocDepth: 4 --- @@ -14,21 +13,22 @@ One of Prisma Client's components is the [Query Engine](./prisma-engines/query-e ## Driver adapters -Prisma Client can connect and run queries against your database using other JavaScript database drivers using **driver adapters**. Adapters act as _translators_ between Prisma Client and the JavaScript database driver. +Prisma Client can connect and run queries against your database using JavaScript database drivers using **driver adapters**. Adapters act as _translators_ between Prisma Client and the JavaScript database driver. + +Prisma will use the Query Engine to transform the Prisma Client query to SQL and run the generated SQL queries via the JavaScript database driver. ![Query flow from the user application to the database using Prisma Client and driver adapters](./images//drivers/qe-query-engine-adapter.png) -Prisma will use the Query Engine to transform the Prisma Client query to SQL and run the generated SQL queries via the JavaScript database driver. +### Serverless driver adapters -Prisma maintains the following driver adapters: +- [Neon](/guides/database/neon#how-to-use-the-neon-serverless-driver-with-prisma-preview) +- [PlanetScale](/guides/database/planetscale#how-to-use-the-planetscale-serverless-driver-with-prisma-preview) -- Serverless driver adapters: +### Database driver adapters - - [Neon](https://github.com/prisma/prisma/tree/main/packages/adapter-neon) - - [PlanetScale](https://github.com/prisma/prisma/tree/main/packages/adapter-planetscale) +- [Turso](/guides/database/turso#connect-and-query-your-primary-database) -- Database driver adapters: - - [Turso](https://github.com/prisma/prisma/tree/main/packages/adapter-libsql) +### How to use driver adapters To use this feature: diff --git a/content/300-guides/050-database/850-planetscale.mdx b/content/300-guides/050-database/850-planetscale.mdx index 73db12d3fb..c47bf0fd00 100644 --- a/content/300-guides/050-database/850-planetscale.mdx +++ b/content/300-guides/050-database/850-planetscale.mdx @@ -229,7 +229,7 @@ For a more detailed example, see the [Getting Started guide for PlanetScale](/ge The [PlanetScale serverless driver](https://planetscale.com/docs/tutorials/planetscale-serverless-driver) provides a way of communicating with your database and executing queries over HTTP. -You can use Prisma along with the PlanetScale serverless driver using a [driver adapter](/concepts/components/drivers#driver-adapters) . A driver adapter allows you to use a different database driver to communicate with your database from the default driver Prisma provides. +You can use Prisma along with the PlanetScale serverless driver using the [`@prisma/adapter-planetscale`](https://www.npmjs.com/package/@prisma/adapter-planetscale) driver adapter. The driver adapter allows you to communicate with your database over HTTP. @@ -256,12 +256,12 @@ npx prisma generate Ensure you update the host value in your connection string to `aws.connect.psdb.cloud`. You can learn more about this [here](https://planetscale.com/docs/tutorials/planetscale-serverless-driver#add-and-use-the-planetscale-serverless-driver-for-javascript-to-your-project). - - ```bash DATABASE_URL='mysql://johndoe:strongpassword@aws.connect.psdb.cloud/clear_nightsky?sslaccept=strict' ``` + + Install the Prisma adapter for PlanetScale, PlanetScale serverless driver and `undici` packages: ```sh diff --git a/content/400-reference/200-api-reference/050-prisma-client-reference.mdx b/content/400-reference/200-api-reference/050-prisma-client-reference.mdx index 3c00369c04..b4d21b15c6 100644 --- a/content/400-reference/200-api-reference/050-prisma-client-reference.mdx +++ b/content/400-reference/200-api-reference/050-prisma-client-reference.mdx @@ -61,6 +61,34 @@ This section describes the `PrismaClient` constructor and its parameters. - Parameters are validated at runtime. +### adapter + +Defines an instance of a [driver adapter](/concepts/components/drivers#driver-adapters). See also [Drivers](/concepts/components/drivers) . + +This is available from version 5.4.0 and newer. + +This feature is currently in Preview behind the `driverAdapters` feature flag. + +#### Example + +The example below uses the [Neon driver adapter](/guides/database/neon#how-to-use-the-neon-serverless-driver-with-prisma-preview) + +```ts +import { Pool, neonConfig } from '@neondatabase/serverless' +import { PrismaNeon } from '@prisma/adapter-neon' +import { PrismaClient } from '@prisma/client' +import dotenv from 'dotenv' +import ws from 'ws' + +dotenv.config() +neonConfig.webSocketConstructor = ws +const connectionString = `${process.env.DATABASE_URL}` + +const pool = new Pool({ connectionString }) +const adapter = new PrismaNeon(pool) +const prisma = new PrismaClient({ adapter }) +``` + ### datasources Programmatically overrides properties of the `datasource` block in the `schema.prisma` file - for example, as part of an integration test. See also: [Data sources](/concepts/components/prisma-schema/data-sources) @@ -123,34 +151,6 @@ const prisma = new PrismaClient({ }) ``` -### adapter - -Defines an instance of a [driver adapter](/concepts/components/drivers#driver-adapters). See also [Drivers](/concepts/components/drivers) . - -This is available from version 5.4.0 and newer. - -This feature is currently in Preview behind the `driverAdapters` feature flag. - -#### Example - -The example below uses the [Neon driver adapter](/guides/database/neon#how-to-use-the-neon-serverless-driver-with-prisma-preview) - -```ts -import { Pool, neonConfig } from '@neondatabase/serverless' -import { PrismaNeon } from '@prisma/adapter-neon' -import { PrismaClient } from '@prisma/client' -import dotenv from 'dotenv' -import ws from 'ws' - -dotenv.config() -neonConfig.webSocketConstructor = ws -const connectionString = `${process.env.DATABASE_URL}` - -const pool = new Pool({ connectionString }) -const adapter = new PrismaNeon(pool) -const prisma = new PrismaClient({ adapter }) -``` - ### log Determines the type and level of logging. See also: [Logging](/concepts/components/prisma-client/working-with-prismaclient/logging)