Next.js and Hyperdrive
Hello there! Has anyone managed to make a NextJS app hosted on Cloudflare Pages to fetch its Postgres database through Hyperdrive?
11 Replies
Are you using Postgres.js? It’s what we recommend for compatibility with Pages
I managed to obtain the HYPERDRIVE env var from my pages, and I didn't yet tried to query it with Prisma. Don't you think it could work with the Neon serverless driver for Prisma (instead of Postgres.js)?
GitHub
GitHub - neondatabase/serverless: Connect to Neon PostgreSQL from s...
Connect to Neon PostgreSQL from serverless/worker/edge functions - neondatabase/serverless
I was using it before wrapping our DB into Hyperdrive
They claim to be "A drop-in replacement for node-postgres, aka pg (on which it's based)"
The Neon serverless driver is slower than using Hyperdrive: https://discord.com/channels/595317990191398933/1150557986239021106/1278695196216922173
Hey @Matt! I meant using the Neon serverless driver to query the Hyperdrive endpoint
Does Postgres.js integrate with Prisma?
Yeah - it isn’t compatible. The serverless driver exists because most serverless platforms don’t have Hyperdrive. The post I linked explains this (highly suggest you read it!)
I did read it earlier today, my main issue right now is to connect to the Hyperdrive endpoint with Prisma on Cloudflare Pages. Do you know of any resource about that?
Btw I’ve got a lot of errors while trying it, both in local and on edge it was raising about « cloudflare:sockets » not being available. I haven’t been able to make it work at all.
Any example of implementation?
Cross-posted to next-on-pages, https://discord.com/channels/595317990191398933/1135899572141568050/1280529649394516019
This isn't Hyperdrive related because attempting to connect to a database directly (without Hyperdrive) also causes the issue you bring up (I've repro-ed)
Hey there, just came across your post here. May I know if you have find a solution for this? Thanks
Hey there! We moved our API to a worker, so it should work now, but we haven't implemented Hyperdrive on it it yet