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
Pages doesn't support the hyperdrive binding
Why not? Any ETA?
That basically means we are locked to neon database for pages deployments?
Pages generally lags behind in bindings and worker features (like logpush)
Could use a worker and a service binding from Pages to that worker
Is there a github issue I can track for support?
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)
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.
yea you need node_compat which just isn't an option with Pages
Is there any way at the current moment I could use my postgres database in my CF Pages?
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
Do you know if Neon databases work in Cloudflare Pages?
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
This has been extremely helpful. Thanks for sorting this all out.
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
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?
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
Seems i'm venturing into unknown territory, perhaps i better switch to Neon
Any update on this @Chaika ?
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
and postgres.js is fully supported now and just needs the nodejs_compat flag: https://discord.com/channels/595317990191398933/1150557986239021106/1243324127901777980, with a nice supported drivers list too: https://developers.cloudflare.com/hyperdrive/configuration/connect-to-postgres/#supported-drivers
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?
@Dario do we support Hyperdrive in platform proxy?
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)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.looks like svelte has a pretty old wrangler - may be why it isn't there
3.28.4?
yep
...interesting...
@Dario do we have comms with them? Can we get them to update?
yes we have, I can ping them π
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.
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
...I'm glad you solved all the above π
regarding tomorrow soon.....
npm run dev
.... I "probably".... I can't guarantee that it's working.... π€
I'll have a have a quick look