#Is there anyway to use any SQL database on Prisma (Next.JS)?

1 messages · Page 1 of 1 (latest)

quartz barn
#

We are currently trying to make a project but currently are stuck with using Prisma on Next.JS without Prisma Accelerate.

wheat mesa
#

Bump

random dawn
#

Hi there, please don't bump threads.

To your question, could you provide more information? What issues are you running into? What have you tried already? Where is your application being deployed? What kind of database are you using and where have you deployed it?

The more information you can provide, the better we can help

quartz barn
# random dawn Hi there, please don't bump threads. To your question, could you provide more ...
Server Error
PrismaClientValidationError: PrismaClient failed to initialize because it wasn't configured to run in this environment (Vercel Edge Functions or Edge Middleware).
In order to run Prisma Client in an edge runtime, you will need to configure one of the following options:
- Enable Driver Adapters: https://pris.ly/d/driver-adapters
- Enable Accelerate: https://pris.ly/d/accelerate

We get this error however we do not want to use Prisma Accelerate currently and In the page it was said that pg currently doesn't work. I was wondering if there was anyway to overcome this issue.

Our application is currently deployed locally and we are using PostgreSQL on an Ubuntu Server Focal

random dawn
#

Have you enabled the driver adapters preview feature? https://pris.ly/d/driver-adapters

Prisma

Learn how Prisma connects to your database using the built-in drivers and how you can use Prisma along with other JavaScript database drivers using driver adapters (Preview)

#

Also, as you said, pg isn't supported in the Vercel edge environment. https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-vercel#using-an-edge-compatible-driver

You may want to try @prisma/pg-worker and @prisma/adapter-pg-worker and see if that resolves your issues. https://www.npmjs.com/package/@prisma/adapter-pg-worker https://www.npmjs.com/package/@prisma/pg-worker

Prisma

Learn the things you need to know in order to deploy an Edge function that uses Prisma Client for talking to a database.

quartz barn
# random dawn Also, as you said, `pg` isn't supported in the Vercel edge environment. https://...

Hey Jon,

I just tried @prisma/pg-worker and @prisma/adapter-pg-adapter and got

Build Error
Failed to compile

Next.js (14.2.0-canary.62)
cloudflare:sockets
Module build failed: UnhandledSchemeError: Reading from "cloudflare:sockets" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "cloudflare:" URIs.

And here is my Next.JS info

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103
  Available memory (MB): 8192
  Available CPU cores: 8
Binaries:
  Node: 20.10.0
  npm: 10.2.5
  Yarn: 1.22.11
  pnpm: 6.14.6
Relevant Packages:
  next: 14.2.0-canary.62 // Latest available version is detected (14.2.0-canary.62).
  eslint-config-next: 14.1.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.4
Next.js Config:
  output: N/A

And how i'm currently initiating Prisma Client

import { Pool } from '@prisma/pg-worker'
import { PrismaPg } from '@prisma/adapter-pg-worker'
import { PrismaClient } from '@prisma/client'

// Learn more about instantiating PrismaClient in Next.js here: https://www.prisma.io/docs/data-platform/accelerate/getting-started

const pool = new Pool({ connectionString: process.env.DATABASE_URL })
const adapter = new PrismaPg(pool)

const prismaClientSingleton = () => new PrismaClient({ adapter })

type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;

const globalForPrisma = globalThis as unknown as {
  prisma: PrismaClientSingleton | undefined;
};

const prisma = globalForPrisma.prisma ?? prismaClientSingleton();


export default prisma;

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
#

If you need anymore information, let me know.

random dawn
#

Let me confirm with our engineering team about our Vercel limitations around PostgreSQL

quartz barn
random dawn
#

So the Vercel runtime has limited support for drivers. A few work. Those are noted here: https://www.prisma.io/docs/orm/prisma-client/deployment/edge/deploy-to-vercel#using-an-edge-compatible-driver

If your database is in Neon or Vercel Postgres, you can use the Neon database driver and Neon driver adapter.

If you’re using PlanetScale, you can use the PlanetScale driver and driver adapter.

If you’re using Turso, you can use the libsql client and driver adapter.

Unfortunately, those are the only options. This is due to TCP connections not being available in the Vercel Edge environment, which makes most existing db clients not work.

Prisma

Learn the things you need to know in order to deploy an Edge function that uses Prisma Client for talking to a database.

wheat mesa
#

@quartz barn

quartz barn
random dawn
quartz barn
random dawn
quartz barn
random dawn
quartz barn