vercel-labs / function-database-latency

Visualize the latency of databases from Vercel Functions.
https://db-latency.vercel.app/
171 stars 29 forks source link

Add Neon with Drizzle, Prisma, and Node.js support #49

Closed evanshortiss closed 4 months ago

evanshortiss commented 4 months ago

@jawj @kelvich can you take a look? Two outstanding questions:

  1. Is there a seed script required? I don't see prisma migrate being called anywhere for other platforms, so maybe not?
  2. Prisma runs into an issue when setting neonConfig.webSocketConstructor = ws. It appears that the browser.js file is loaded. A user in the Neon Discord ran into this today, too, but we didn't get to the bottom of it. It seems to happen when runtime is edge

Tested using these commands

export NEON_DATABASE_URL='postgresql://user:pass@hostname/neondb?sslmode=require' 
npx prisma migrate dev
npm run dev
vercel[bot] commented 4 months ago

@evanshortiss is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

kelvich commented 4 months ago

Why does this PR includes prisma-client sources? can't in be just npm install @prisma/client?

jawj commented 4 months ago

I'm a little bit confused about what environment(s) this is supposed to run in. Is it both edge functions (i.e. v8 isolates, has WebSockets, no TCP) and lambdas (i.e. Node, has TCP, no WebSockets)?

In V8 isolates things will likely go wrong if you even try to import ws or undici, and certainly if you pass the relevant WebSocket constructor to our library.

In Node/Lambda I think things will go wrong unless you do both those things.

Also: what @kelvich said.

leerob commented 4 months ago

@jawj it's both:

evanshortiss commented 4 months ago

@kelvich can you clarify what you mean?

Do you mean why the relative import for the Prisma client? With Prisma you need to generate a custom client within your project. Usually, it's not checked in AFAIK, but in this repository, I believe it's necessary since we don't control build/deploy and we'd end up with conflicting clients in the default location - you can see other platforms doing it too in the repo.

evanshortiss commented 4 months ago

@jawj, right, and I'm not using the Pool constructor. I don't need ws either way. This is what happens when coding late. Removed it 😄

vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
edge-data-latency ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 9, 2024 2:01am