-
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
59 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -225,6 +225,64 @@ model User { | |
|
||
For a more detailed example, see the [Getting Started guide for PlanetScale](/getting-started/setup-prisma/add-to-existing-project/relational-databases/introspection-typescript-planetscale). | ||
|
||
## How to use the PlanetScale serverless driver with Prisma (Preview) | ||
|
||
The [PlanetScale serverless driver](https://planetscale.com/docs/tutorials/planetscale-serverless-driver) provides a means of accessing your database and executing queries over HTTP. Prisma by default uses TCP to access your database and execute queries. You can use Prisma along with the PlanetScale driver using a [driver adapter](/concepts/components/drivers) <span class="concept"></span>. A driver adapter allows you to use a different database driver, from the default Prisma provides, to access your database. | ||
|
||
<Admonition> | ||
|
||
This feature is available 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 | ||
``` | ||
|
||
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:[email protected]/clear_nightsky?sslaccept=strict' | ||
``` | ||
|
||
Install the Prisma adapter for PlanetScale, PlanetScale serverless driver and undici: | ||
|
||
```sh | ||
npm install @prisma/adapter-planetscale @planetscale/database undici | ||
``` | ||
|
||
> Prisma ORM supports Node 16 and up. In Node 18 and up, `undici` is not needed. | ||
Update your Prisma Client instance to use the PlanetScale database 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 as you normally would. | ||
|
||
## More on using PlanetScale with Prisma | ||
|
||
The fastest way to start using PlanetScale with Prisma is to refer to our Getting Started documentation: | ||
|