DEV Community

Anden Acitelli
Anden Acitelli

Posted on

Guide: Connecting Prisma to Vercel Postgres

Overview

This post will walk you through successfully connecting Prisma to Vercel's Postgres implementation.

I work for Akkio, where I'm building out a no-code predictive AI platform. If you're looking to harness the power of AI without needing a data scientist, give us a try!

Step 1: Create a Database

First, create a PostgreSQL database through Vercel.
Image description

This will automatically add all the relevant environment variables you'll need to the Vercel project as well, which will come in handy a bit later.

Image description

Step 2: Find Your Credentials

The way I recommend doing this is as follows.

  1. Install the Vercel CLI. npm i -g vercel should do the trick.
  2. Link your project. vercel link will walk you through the process.
  3. Pull your variables down. vercel env pull is the command you're looking for.

At this point, you'll have a .env file locally that you can use to your exact values. The relevant variable you're looking for is POSTGRES_PRISMA_URL.

Step 3: Plug It In!

Modify your prisma.schema so it looks like this:

datasource db {
  provider = "postgresql"
  url      = env("POSTGRES_PRISMA_URL")
}
Enter fullscreen mode Exit fullscreen mode

This environment variable configures some stuff in the URL so that Prisma can properly connect to it. Enjoy!

Top comments (1)

Collapse
 
blackstorm profile image

If you are using vercel's postgres

datasource db {
  provider  = "postgresql"
  url       = env("POSTGRES_PRISMA_URL")
  directUrl = env("POSTGRES_URL_NON_POOLING")
}

Enter fullscreen mode Exit fullscreen mode