Is there Hyperdrive Support?

I'd like to use hyperdrive to manage the connections to my postgresql instance. I'm using sveltekit with adapter-cloudflare. Can I use Hyperdrive with cloudflare pages?
16 Replies
Chaika
Chaika4mo ago
Pages doesn't support the hyperdrive binding
Paul
Paul4mo ago
Why not? Any ETA? That basically means we are locked to neon database for pages deployments?
Chaika
Chaika4mo ago
Pages generally lags behind in bindings and worker features (like logpush) Could use a worker and a service binding from Pages to that worker
Paul
Paul4mo ago
Is there a github issue I can track for support?
Chaika
Chaika4mo ago
afaik the pages team hasn't said they're working on it yet, hyperdrive is also still in beta. There is more stuff blocking it -- pg for example also requires node_compat which isn't possible in Pages, only Workers (Pages only has the nodejs compat flag, which is different)
Paul
Paul4mo ago
I'm noticing that, i've been at it for a few hours trying to connect to a postgres instance from my CF Pages. Has anyone ever gotten this to work? pg has dependencies on fs,tls and such, and it's complaining during build.
Chaika
Chaika4mo ago
yea you need node_compat which just isn't an option with Pages
Paul
Paul4mo ago
Is there any way at the current moment I could use my postgres database in my CF Pages?
Chaika
Chaika4mo ago
I haven't tried it, but I know recently there was talk about this postgres driver which works with just the nodejs_compat flag: https://github.com/porsager/postgres/pull/796 wouldn't have hyperdrive though
Paul
Paul4mo ago
Do you know if Neon databases work in Cloudflare Pages?
Chaika
Chaika4mo ago
I use their serverless driver in Workers and it works ok, I don't think it requires node compat? It doesn't seem to say so Its using just https/websockets
Paul
Paul4mo ago
This has been extremely helpful. Thanks for sorting this all out.
Chaika
Chaika4mo ago
yeaa sadly right now it's not a great experience, with the different node_compat and bindings support. Longer term there is plans on merging Pages & Workers into one unified project ("convergence"), but that's a while out. There was some talk of trying to get node_compat to Pages added but that PR is still stuck iirc if you're going to use neon there's a normal endpoint and a connection pooling endpoint, you'd want to use the connection pooling endpoint for Workers/Pages (short lived) -> https://neon.tech/docs/connect/connection-pooling
Paul
Paul4mo ago
I've got it working with postgres that you linked from earlier, but now I'm wondering if I should only connect during the handler and disconnect after? -- or do you think it's okay to have a long lived database connection outside the handler scope? I'm assuming if i initialize and connect from global scope, it can be re-used for any calls?
Chaika
Chaika4mo ago
usually rare for two different users to hit the same isolate/worker unless its the same person/browser keepalive and keeping promises and connections in the global scope causes issues that's part of the reason hyperdrive exists
Paul
Paul4mo ago
Seems i'm venturing into unknown territory, perhaps i better switch to Neon