Replies: 9 comments 28 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. |
Beta Was this translation helpful? Give feedback.
-
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). |
Beta Was this translation helpful? Give feedback.
-
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 expected const prisma = new PrismaClient({ adapter })
await prisma.$queryRaw`SHOW search_path;`;
// search_path is 'public' as NOT expected |
Beta Was this translation helpful? Give feedback.
-
This is cool. Im using Vercel Storage Postgres which itself uses Neon database under the hood. Will this work with Vercel Postgres? |
Beta Was this translation helpful? Give feedback.
-
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:
|
Beta Was this translation helpful? Give feedback.
-
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
***@***.***
|
Beta Was this translation helpful? Give feedback.
-
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 🙏 |
Beta Was this translation helpful? Give feedback.
-
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 👍 |
Beta Was this translation helpful? Give feedback.
-
Facing the same issue on vercel serverless function with neon serverless driver. Very tricky to troubleshoot.
|
Beta Was this translation helpful? Give feedback.
-
Support for the Neon Serverless Driver is in preview behind the
driverAdapters
preview feature.Please share your feedback about
@prisma/adapter-neon
released in v5.4.0 in this issue.Beta Was this translation helpful? Give feedback.
All reactions