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
thomasgauvin
thomasgauvin3mo ago
Are you using Postgres.js? It’s what we recommend for compatibility with Pages
Lila Rest
Lila RestOP3mo ago
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)?
Lila Rest
Lila RestOP3mo ago
GitHub
GitHub - neondatabase/serverless: Connect to Neon PostgreSQL from s...
Connect to Neon PostgreSQL from serverless/worker/edge functions - neondatabase/serverless
Lila Rest
Lila RestOP3mo ago
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)"
elithrar
elithrar3mo ago
The Neon serverless driver is slower than using Hyperdrive: https://discord.com/channels/595317990191398933/1150557986239021106/1278695196216922173
Lila Rest
Lila RestOP3mo ago
Hey @Matt! I meant using the Neon serverless driver to query the Hyperdrive endpoint Does Postgres.js integrate with Prisma?
elithrar
elithrar3mo ago
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!)
Lila Rest
Lila RestOP3mo ago
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?
thomasgauvin
thomasgauvin3mo ago
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)
anyuj
anyuj2mo ago
Hey there, just came across your post here. May I know if you have find a solution for this? Thanks
Lila Rest
Lila RestOP2mo ago
Hey there! We moved our API to a worker, so it should work now, but we haven't implemented Hyperdrive on it it yet
Want results from more Discord servers?
Add your server