From caadb4136222f7fa7a763a23b84ec36f49750264 Mon Sep 17 00:00:00 2001 From: ruheni Date: Wed, 1 Nov 2023 00:45:43 +0100 Subject: [PATCH] reorder content structure --- .../200-concepts/100-components/drivers.mdx | 118 ++---------------- .../050-database/850-planetscale.mdx | 66 +++++++++- 2 files changed, 72 insertions(+), 112 deletions(-) diff --git a/content/200-concepts/100-components/drivers.mdx b/content/200-concepts/100-components/drivers.mdx index 8d9424d21c..7d191aa138 100644 --- a/content/200-concepts/100-components/drivers.mdx +++ b/content/200-concepts/100-components/drivers.mdx @@ -22,9 +22,9 @@ Prisma will use the Query Engine to transform the Prisma Client query to SQL and Prisma maintains the following driver adapters: -- [Neon](#neon-serverless-driver) -- [PlanetScale](#planetscale-serverless-driver) -- [Turso](#turso-early-access) +- [Neon](https://github.com/prisma/prisma/tree/main/packages/adapter-neon) +- [PlanetScale](https://github.com/prisma/prisma/tree/main/packages/adapter-planetscale) +- [Turso](https://github.com/prisma/prisma/tree/main/packages/adapter-libsql) To use this feature: @@ -43,112 +43,8 @@ To use this feature: npx prisma generate ``` -### Serverless drivers +Refer to the following pages to learn more how to use the specific driver adapters with the specific database providers: -Several database providers enable the use of different protocols, such as HTTP and WebSocket, to connect to your database. Example database providers include Neon and PlanetScale. - -#### Neon Serverless Driver - -The [Neon serverless driver](https://neon.tech/docs/serverless/serverless-driver) provides a way of communicating with your database and executing queries over HTTP and WebSockets. - -To use the Neon serverless driver with Prisma: - -1. Install the Prisma driver adapter for Neon, Neon serverless driver and `ws` packages: - - ```sh - npm install @prisma/adapter-neon @neondatabase/serverless ws - ``` - -2. Update your Prisma Client instance: - - ```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 }) - ``` - -We would appreciate your feedback on the Neon serverless driver adapter. Let us know what you think by leaving a comment in [this GitHub issue](https://github.com/prisma/prisma/discussions/21346). - -#### PlanetScale Serverless Driver - -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. - -To use the PlanetScale serverless driver with Prisma: - -1. Install the Prisma driver adapter for PlanetScale, PlanetScale serverless driver and undici packages: - - ```sh - npm install @prisma/adapter-planetscale @planetscale/database undici - ``` - - - -When using an older version of Node.js, you can provide a custom fetch function implementation. We recommend the `undici` package on which Node's built-in fetch is based. Node.js version 18 includes a built-in global `fetch` function. Node.js versions 18 and newer include `undici` and you don't have to install the package. See [System requirements](/reference/system-requirements) - -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). For example: - -```bash -DATABASE_URL='mysql://johndoe:strongpassword@aws.connect.psdb.cloud/clear_nightsky?sslaccept=strict' -``` - - - -2. Update your Prisma Client instance: - - ```ts - import { connect } from '@planetscale/database' - import { PrismaPlanetScale } from '@prisma/adapter-planetscale' - import { PrismaClient } from '@prisma/client' - import dotenv from 'dotenv' - import { fetch as undiciFetch } from 'undici' - - dotenv.config() - const connectionString = `${process.env.DATABASE_URL}` - - const connection = connect({ url: connectionString, fetch: undiciFetch }) - const adapter = new PrismaPlanetScale(connection) - const prisma = new PrismaClient({ adapter }) - ``` - -We would appreciate your feedback on the PlanetScale serverless driver adapter. Let us know what you think by leaving a comment in [this GitHub issue](https://github.com/prisma/prisma/discussions/21347). - -### Database drivers - -#### Turso (Early Access) - -Install the Prisma driver adapter for LibSQL and LibSQL packages: - -```sh -npm install @prisma/adapter-libsql @libsql/client -``` - -Update your Prisma Client instance: - -```ts -import { PrismaClient } from '@prisma/client' -import { PrismaLibSQL } from '@prisma/adapter-libsql' -import { createClient } from '@libsql/client' -import dotenv from 'dotenv' - -dotenv.config() - -const libsql = createClient({ - url: `${process.env.TURSO_DATABASE_URL}`, - authToken: `${process.env.TURSO_AUTH_TOKEN}`, -}) - -const adapter = new PrismaLibSQL(libsql) -const prisma = new PrismaClient({ adapter }) -``` - -We would appreciate your feedback on the Turso database driver adapter. Let us know what you think by leaving a comment in [this GitHub issue](https://github.com/prisma/prisma/discussions/21345). +- [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) +- [Turso](/guides/database/turso#connect-and-query-your-primary-database) diff --git a/content/300-guides/050-database/850-planetscale.mdx b/content/300-guides/050-database/850-planetscale.mdx index 06de7ae713..078ac5bef8 100644 --- a/content/300-guides/050-database/850-planetscale.mdx +++ b/content/300-guides/050-database/850-planetscale.mdx @@ -227,7 +227,71 @@ For a more detailed example, see the [Getting Started guide for PlanetScale](/ge ## How to use the PlanetScale serverless driver with Prisma (Preview) -To learn more on how you can use PlanetScale's serverless driver with Prisma, refer to [this page](/concepts/components/drivers#planetscale-serverless-driver). +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. + + + +This feature is available in Preview from Prisma versions 5.4.2 and later. + + + +To get started, enable the `driverAdapters` Preview feature flag: + +```prisma +generator client { + provider = "prisma-client-js" + previewFeatures = ["driverAdapters"] +} +``` + +Generate Prisma Client: + +```sh +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 +npm install @prisma/adapter-planetscale @planetscale/database undici +``` + + + +When using an older version of Node.js, you can provide a custom fetch function implementation. We recommend the `undici` package on which Node's built-in fetch is based. Node.js version 18 includes a built-in global `fetch` function. Node.js versions 18 and newer include `undici` and you don't have to install the package. See [System requirements](/reference/system-requirements) + + + +Update your Prisma Client instance to use the PlanetScale serverless driver: + +```ts +import { connect } from '@planetscale/database' +import { PrismaPlanetScale } from '@prisma/adapter-planetscale' +import { PrismaClient } from '@prisma/client' +import dotenv from 'dotenv' +import { fetch as undiciFetch } from 'undici' + +dotenv.config() +const connectionString = `${process.env.DATABASE_URL}` + +const connection = connect({ url: connectionString, fetch: undiciFetch }) +const adapter = new PrismaPlanetScale(connection) +const prisma = new PrismaClient({ adapter }) +``` + +You can then use Prisma Client as you normally would with full type-safety. ## More on using PlanetScale with Prisma