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?
31 Replies
Chaika
Chaikaβ€’10mo ago
Pages doesn't support the hyperdrive binding
Paul
PaulOPβ€’10mo ago
Why not? Any ETA? That basically means we are locked to neon database for pages deployments?
Chaika
Chaikaβ€’10mo 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
PaulOPβ€’10mo ago
Is there a github issue I can track for support?
Chaika
Chaikaβ€’10mo 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
PaulOPβ€’10mo 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
Chaikaβ€’10mo ago
yea you need node_compat which just isn't an option with Pages
Paul
PaulOPβ€’10mo ago
Is there any way at the current moment I could use my postgres database in my CF Pages?
Chaika
Chaikaβ€’10mo 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
PaulOPβ€’10mo ago
Do you know if Neon databases work in Cloudflare Pages?
Chaika
Chaikaβ€’10mo 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
PaulOPβ€’10mo ago
This has been extremely helpful. Thanks for sorting this all out.
Chaika
Chaikaβ€’10mo 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
PaulOPβ€’10mo 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
Chaikaβ€’10mo 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
PaulOPβ€’6mo ago
Seems i'm venturing into unknown territory, perhaps i better switch to Neon Any update on this @Chaika ?
Walshy
Walshyβ€’6mo ago
yes hyperdrive is supported I'm not fully sure if it's in the UI yet let me check wrangler.. looks like wrangler does yes but not in the UI yet
Chaika
Chaikaβ€’6mo ago
Paul
PaulOPβ€’6mo ago
BIG NEWS. Can’t wait to try this out. Now hopefully there are no unforeseen issues with SvelteKit and adapter-cloudflare I am unable to return the HYPERDRIVE binding from within the getPlatformProxy, any suggestions?
Walshy
Walshyβ€’6mo ago
@Dario do we support Hyperdrive in platform proxy?
Dario
Darioβ€’6mo ago
mh... probably.... getPlatformProxy gets the configs to the toml file, passes them to miniflare and receives back proxies to the bindings, so it hyperdrive is supported in local (non-remote) mode then I think it should probably be supported by getPlatformProxy too... sorry for the unsure answer... I guess we'd have to try to find out πŸ˜… (and document/test)
Paul
PaulOPβ€’6mo ago
I have no idea haha, but i am seeing that hyperdrive is not included here: https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/api/dev.ts wrangler pages dev is working great for me, but since I am using SvelteKit i need to use npm run dev, and there I am required to use getPlatformProxy in my hooks handler to get my platform env. i can just have a slower iteration loop for now, at least i have it working for prod!!! this is big. Please let me know if there are any issues i can subscribe to.
Walshy
Walshyβ€’6mo ago
looks like svelte has a pretty old wrangler - may be why it isn't there
Paul
PaulOPβ€’6mo ago
3.28.4?
Walshy
Walshyβ€’6mo ago
yep
Paul
PaulOPβ€’6mo ago
...interesting...
Walshy
Walshyβ€’6mo ago
@Dario do we have comms with them? Can we get them to update?
Dario
Darioβ€’6mo ago
yes we have, I can ping them πŸ‘
Dario
Darioβ€’6mo ago
I can see that there wrangler is a peer dependency set as ^3.28.4 (https://github.com/sveltejs/kit/blob/25acb1d9fce998dccd8050b93cf4142c2b082611/packages/adapter-cloudflare/package.json#L47), so @Paul you should just be able to install the latest and svelte kit should pick that one up, no?
GitHub
kit/packages/adapter-cloudflare/package.json at 25acb1d9fce998dccd8...
web development, streamlined. Contribute to sveltejs/kit development by creating an account on GitHub.
Paul
PaulOPβ€’6mo ago
Yep, i am seeing in my "node_modules" that wrangler is set to 3.59.0. I am still unfortunately not seeing the binding from getPlatformProxy though. Dang, it's actually not working when I deploy to pages. It's only working when I wrangler pages dev locally. I have also locally pulled down the adapter-cloudflare and updated the package.json with the newest wrangler version, then pointed my SvelteKit project to use the local adapter-cloudflare, still no HYPERDRIVE binding in my platform.env For getting it to work when deploying to Pages, do I need to add it as a binding like I do with all the other features (D1, R2, etc), on the Page project's Settings page? If so, there is no Hyperdrive section. Ok, deployment is solved and the HYPERDRIVE binding is now showing for the live site. The problem was that my wrangler.toml was not being published along with my asset bundle in my GitHub Action (there was an error due to a missing pages_build_output_dir field. I also enabled wrangler v3 in the github action config). After getting the wrangler.toml config properly setup, the Github Action was able to publish along with my asset bundle. Now the wrangler.toml is used as the "source of truth" for project config instead of the Cloudflare Dashboard. Now, if I could just figure out how to get SvelteKit to notice the binding locally during my npm run dev...
Dario
Darioβ€’6mo ago
I'm glad you solved all the above πŸ˜„ regarding npm run dev.... I "probably".... I can't guarantee that it's working.... πŸ€” I'll have a have a quick look tomorrow soon.....
Want results from more Discord servers?
Add your server