-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
``` | ||
|
||
<Admonition> | ||
|
||
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:[email protected]/clear_nightsky?sslaccept=strict' | ||
``` | ||
|
||
</Admonition> | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) <span class="concept"></span>. A driver adapter allows you to use a different database driver to communicate with your database from the default driver Prisma provides. | ||
|
||
<Admonition> | ||
|
||
This feature is available in Preview from Prisma versions 5.4.2 and later. | ||
|
||
</Admonition> | ||
|
||
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 | ||
``` | ||
|
||
<Admonition> | ||
|
||
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). | ||
|
||
</Admonition> | ||
|
||
```bash | ||
DATABASE_URL='mysql://johndoe:[email protected]/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 | ||
``` | ||
|
||
<Admonition> | ||
|
||
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) | ||
|
||
</Admonition> | ||
|
||
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 | ||
|
||
|