Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Neon to database guides #4846

Closed
wants to merge 2 commits into from

Conversation

raoufchebri
Copy link
Contributor

Describe this PR

This guide explains how to connect Prisma to Neon, establish connections when using Prisma Client in serverless functions, and resolve connection timeout issues.

@vercel
Copy link

vercel bot commented Jun 7, 2023

@raoufchebri is attempting to deploy a commit to the Prisma Team on Vercel.

A member of the Team first needs to authorize it.

@raoufchebri raoufchebri changed the title Create 890-Neon Add Neon to database guides Jun 7, 2023
Copy link
Contributor

@ruheni ruheni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left two comments.

TL;DR, let's borrow from the Prisma with Supabase guide and add a section comparing Neon with PostgreSQL, and a "Special considerations" section for information on pooled vs non-pooled connection strings and how to use them with Prisma.

Comment on lines +23 to +57
## Prerequisites

- A Neon project. See [Create a project](../manage/projects#create-a-project).
- A Prisma project. See [Set up Prisma](https://www.prisma.io/docs/getting-started/setup-prisma), in the _Prisma documentation_.

## Connect to Neon from Prisma

To establish a basic connection from Prisma to Neon, perform the following steps:

1. Retrieve your Neon connection string. In the **Connection Details** widget on the Neon **Dashboard**, select a branch, a user, and the database you want to connect to. A connection string is constructed for you.
![Connection details widget](/docs/connect/connection_details.png)
The connection string includes the user name, password, hostname, and database name.

2. Add the following lines to your `prisma/schema.prisma` file to identify the data source and database URL:

```typescript
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
```

3. Add a `DATABASE_URL` variable to your `.env` file and set it to the Neon connection string that you copied in the previous step. Your setting will appear similar to the following:

<CodeBlock shouldWrap>

```text
DATABASE_URL="postgres://daniel:<password>@ep-mute-rain-952417.us-east-2.aws.neon.tech/neondb"
```

</CodeBlock>

<Admonition type="important">
If you are using Prisma Client from a serverless function, see [Connect from serverless functions](#connect-from-serverless-functions). To adjust your connection string to avoid connection timeouts issues, see [Connection timeouts](#connection-timeouts).
</Admonition>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do away with this section.

A section on "Commonalities with other database providers" would be valuable (Example: Using Prisma with Supabase)

If you are using Prisma Client from a serverless function, see [Connect from serverless functions](#connect-from-serverless-functions). To adjust your connection string to avoid connection timeouts issues, see [Connection timeouts](#connection-timeouts).
</Admonition>

## Connect from serverless functions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this section, we could also borrow from the structure used in the Specific considerations section in the "Using Prisma with Supabase" guide.

We would still distinguish between the two connection strings (pooled and non-pooled) but recommend using the directUrl property in the datasource block.

This is similar to how it's represented in the Neon docs here: https://neon.tech/docs/guides/prisma-migrate#prisma-migrate-with-pgbouncer

@ruheni
Copy link
Contributor

ruheni commented Oct 24, 2023

Closing this in favor of #5397 (Continuation of the existing work in the linked PR)

@ruheni ruheni closed this Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants