Replies: 11 comments 32 replies
|
👋 Hi, @janpio - This feature is very exciting! In non-edge runtimes, it seems like it's working as expected from some initial testing. However, I was curious about whether this works in Vercel Edge runtimes, and it seems like it does not if we use setup code similar to what is provided in the blog article: // Import needed packages
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';
// Setup
dotenv.config()
neonConfig.webSocketConstructor = ws;
const connectionString = `${process.env.DATABASE_URL}`;
// Init prisma client
const pool = new Pool({ connectionString });
const adapter = new PrismaNeon(pool);
const prisma = new PrismaClient({ adapter });
// Use Prisma Client as normal^This doesn't work in edge runtimes (regardless of whether we import from From the TypeScript types (and in the source code of the Prisma client), I see that there is a const connectionString = `${process.env.DATABASE_URL}`;
const connection = neon(connectionString, {
arrayMode: false,
fullResults: true,
});
const adapter = new PrismaNeonHTTP(connection);
return new PrismaClient({ adapter });That looks promising, but I can't quite get it work when passing it to the Prisma client constructor from I just wanted to confirm whether there is a way to use the Neon serverless driver in edge runtimes, or if that's specifically something that you wouldn't expect to work yet. I wasn't sure from the announcement whether this new support for the Neon serverless driver was meant to include support for edge or not (I'm assuming not, but I'd love to be wrong). Thank you in advance! Again, very exciting stuff, and I'm glad the team has been working on enhanced support for serverless/edge. |
|
I'm giving this a try. I'm currently in development and using cockroachdb on AWS Lambda and I'm noticing some cold start slowness and I'm hoping this might be a great fix. (Any one care to opine on the tradeoffs between cockroachdb and neon?) Anyways, I'm trying to run locally and am making some progress. Neon docs seem sketchy on the running locally, but I've pieced together that I can run docker-compose with this https://github.com/neondatabase/neon/tree/main/docker-compose and reach postgres with I guess it's looking to be https. I tried this change to no effect: Any ideas on how to run the pooling locally (for testing purposes). |
|
Does the neon adapter respect the I have a connection string with const prisma = new PrismaClient();
await prisma.$queryRaw`SHOW search_path;`;
// search_path is 'staging' as expectedconst prisma = new PrismaClient({ adapter })
await prisma.$queryRaw`SHOW search_path;`;
// search_path is 'public' as NOT expected |
|
This is cool. Im using Vercel Storage Postgres which itself uses Neon database under the hood. Will this work with Vercel Postgres? |
|
Does the Prisma Client need to be initialized in each request handler when using the prisma adapter or does the adapter handle connecting, using, and closing the objects? From Neon Driver Docs link: I am using Prisma with a Nextjs app on Vercel using Vercel Postgres (neon). I tried following the docs for using prisma with neon serverless driver and tried running locally and I get the following error. I did not initialize the pool or prisma client inside of my handlers, I simply modified the file where I was previously instantiating prisma client: |
|
I did have a type error in the same place, and realized I needed to update
Prisma Client version to latest / same as prisma adapter.
On Sat, Dec 30, 2023 at 1:56 PM iqbal125 ***@***.***> wrote:
@timothywadecook <https://github.com/timothywadecook> Are you getting
this type error in Vscode by any chance?
image.png (view on web)
<https://github.com/prisma/prisma/assets/24860061/d17771b6-d4b6-43f5-972c-577f0d048170>
—
Reply to this email directly, view it on GitHub
<#21346 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJX24FGLPVDCV2YUHNKGWQ3YMBPUJAVCNFSM6AAAAAA5S6FPBSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TSOBQGEZDA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Timothy W Cook
678-371-3074
***@***.***
|
|
Hey 👋 prisma:error All attempts to open a WebSocket to connect to the database failed. Please refer to https://github.com/neondatabase/serverless/blob/main/CONFIG.md#websocketconstructor-typeof-websocket--undefined. Details: ws does not work in the browser. Browser clients must use the native WebSocket object
>>> tRPC Error on 'ad.create' [TRPCError: All attempts to open a WebSocket to connect to the database failed. Please refer to https://github.com/neondatabase/serverless/blob/main/CONFIG.md#websocketconstructor-typeof-websocket--undefined. Details: ws does not work in the browser. Browser clients must use the native WebSocket object] {
code: 'INTERNAL_SERVER_ERROR',
name: 'TRPCError'
}LE: Digging into it a bit, now that neonConfig.webSocketConstructor = WebSocket;Thanks 🙏 |
|
I have the following client in my Next.js app, connecting to a local Postgres database: import { Pool } from '@neondatabase/serverless'
import { PrismaNeon } from '@prisma/adapter-neon'
import { PrismaClient } from '@prisma/client'
export const db = new PrismaClient({
adapter: new PrismaNeon(
new Pool({ connectionString: process.env.DATABASE_URL })
)
})When I try to use this in a Server Action, I get a connection error (I confirmed that the database is up and running by switching back to the original Prisma client config where everything worked): When I use it in middleware (edge runtime), I get a rather vague error: Any help would be appreciated! It's just a hobby project for now, so thought I'd give these new adapters a try and provide some feedback 👍 |
|
Facing the same issue on vercel serverless function with neon serverless driver. Very tricky to troubleshoot. |
|
I installed this adapter to tried to have db on Next Middleware, I got timeout errors, I changed the setup to import { Pool } from "@neondatabase/serverless";
import { PrismaNeon } from "@prisma/adapter-neon";
import { PrismaClient } from "@prisma/client";
const connectionString = `${process.env.DATABASE_URL}`;
const pool = new Pool({ connectionString });
const adapter = new PrismaNeon(pool);
const db = new PrismaClient({ adapter });
export default db;And I remove every part of db from the middleware, also SSR and Midleware requires a different implementation of WS, we can't deal with it, the library must detect if it must use the library provided or Web WS I want to see a stable release of this adapter |
|
The last time I tried this package it worked but I had to disable this adapter because for the serverless function it was more latency using NextJS and Vercel import "dotenv/config";
import { PrismaClient } from "@prisma/client";
// import { PrismaNeon } from "@prisma/adapter-neon";
// import { Pool, neonConfig } from "@neondatabase/serverless";
import { readReplicas } from "@prisma/extension-read-replicas";
// import ws from "ws";
// neonConfig.webSocketConstructor = ws;
// const connectionString = process.env.DATABASE_URL;
// const pool = new Pool({ connectionString });
// const adapter = new PrismaNeon(pool);
const replicas: string[] = [];
for (let i = 1; i <= 30; i++) {
const replica = process.env[`DATABASE_URL_REPLICA${i}`];
if (!replica) break;
replicas.push(replica);
}
declare global {
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
let db: PrismaClient; // Explicitly define the type of db
if (global.prisma) {
db = global.prisma;
} else if (replicas.length > 0) {
db = new PrismaClient().$extends(
readReplicas({
url: replicas,
}),
) as unknown as PrismaClient;
global.prisma = db;
} else {
db = new PrismaClient();
global.prisma = db;
}
export default db; |
Uh oh!
There was an error while loading. Please reload this page.
Support for the Neon Serverless Driver is in preview behind the
driverAdapterspreview feature.Please share your feedback about
@prisma/adapter-neonreleased in v5.4.0 in this issue.All reactions