Skip to content

Commit

Permalink
chore:clean up neon serverless driver section
Browse files Browse the repository at this point in the history
  • Loading branch information
ruheni committed Oct 31, 2023
1 parent 356d727 commit 358d144
Showing 1 changed file with 1 addition and 50 deletions.
51 changes: 1 addition & 50 deletions content/300-guides/050-database/890-neon.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,53 +107,4 @@ DATABASE_URL=postgres://daniel:<password>@ep-mute-rain-952417.us-east-2.aws.neon

## How to use Neon's serverless driver with Prisma (Preview)

The [Neon serverless driver](https://github.com/neondatabase/serverless) is a low-latency Postgres driver for JavaScript and TypeScript that allows you to query data from serverless and edge environments over HTTP or WebSockets in place of TCP. Prisma by default uses TCP.

You can use Prisma along with the Neon serverless 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 communicate with your database.

<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
```

Install the Prisma adapter for Neon, Neon serverless driver and `ws` packages:

```sh
npm install @prisma/adapter-neon @neondatabase/serverless ws
```

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 })
```

You can then use Prisma Client as you normally would with full-type-safety.
To learn more on how you can use Neon's serverless driver with Prisma, refer to [this page](/concepts/components/drivers#neon-serverless-driver).

0 comments on commit 358d144

Please sign in to comment.