Hyperdrive bindings exist in the Pages

Hyperdrive bindings exist in the Pages Projects API under hyperdrive_bindings. You won't be able to use the pg driver, but you can use the Postgres.js driver which only requires the compat flag nodejs_compat (not old node_compat) and it works 🙂
65 Replies
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
James
JamesOP8mo ago
You won't be able to use node_compat and pg, but you can use nodejs_compat and https://github.com/porsager/postgres
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
James
JamesOP8mo ago
won't build how so? node_compat is old and generally not recommended - it's a real shame that hyperdrive launched with drivers requiring it.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
James
JamesOP8mo ago
node_compat is a build-time thing with wrangler. nodejs_compat is a runtime compatibility flag You can't use node_compat with Pages. But you don't need that for the postgres.js driver - it works fine with just nodejs_compat
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
James
JamesOP8mo ago
I'm not familiar with nuxt and how it builds sadly, but cloudflare:sockets definitely works fine with Pages and manual Functions. That sounds to me like Nuxt is doing something odd with the build
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
James
JamesOP8mo ago
lemme write up a quick rundown, one sec For a quick rundown for Pages + Hyperdrive: - Hyperdrive today recommends and works best with the pg driver. Sadly today, this driver requires the old and legacy node_compat build option within wrangler, which limits a lot of functionality with the rest of the ecosystem - Pages doesn't support node_compat, so this driver will not work within Pages (without some serious hacks and building some stuff yourself) - https://github.com/porsager/postgres is a postgres driver that doesn't need the legacy node_compat mode and works just fine with the more modern nodejs_compat compatibility runtime flag - This driver doesn't work 100% with hyperdrive though, due to https://github.com/porsager/postgres/pull/736 and using prepared statements by default - Pages doesn't yet have Hyperdrive config in the UI, but does support in the API and via wrangler.toml This is all a bit confusing and definitely feels like it should still be "beta" to me 😅 cc @Matt @AJR ^ this is some good feedback and DX observations
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
James
JamesOP8mo ago
Honestly my personal recommendation would be to probably avoid Hyperdrive with Pages for now - it's likely too much of a headache, and give them a bit of time to stabilise. Hopefully won't be too long.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
AJR
AJR8mo ago
This is good feedback, much appreciated. Again, we're actively pursuing improvements with postgres.js which would simplify this case a bit it sounds like. No worries, this is all good to hear.
Ping for toast
Ping for toast5mo ago
any updates on this? I'm having a ton of issues with both pg and postgres js and I'd really love to get this working with postgres.js, I'm getting
✘ [ERROR] Uncaught TypeError: Cannot read properties of undefined (reading 'replace')

at queryError
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:871780)
at errored
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:871672)
at null.<anonymous>
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:867204)
at done
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:881958)
✘ [ERROR] Uncaught TypeError: Cannot read properties of undefined (reading 'replace')

at queryError
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:871780)
at errored
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:871672)
at null.<anonymous>
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:867204)
at done
(file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-vfuZ5f/chunks/runtime.mjs:1:881958)
with pg, I'm getting
TypeError: this.stream.once is not a function
at jd.connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:929175)
at Client._connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:952418)
at Client.connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:953140)
at dm.newClient (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:964508)
at dm.connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:963874)
at PostgresDriver.acquireConnection (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:849415)
at RuntimeDriver.acquireConnection (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:814312)
at async DefaultConnectionProvider.provideConnection (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:812940)
at async Object.fn (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/build/index-CvHsH36j.mjs:1:18140)
at null.<anonymous> (async file:///Users/evan/Code/pinlog/.wrangler/tmp/dev-6mfei5/a8mn73yuqfn.js:40924:82)
TypeError: this.stream.once is not a function
at jd.connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:929175)
at Client._connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:952418)
at Client.connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:953140)
at dm.newClient (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:964508)
at dm.connect (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:963874)
at PostgresDriver.acquireConnection (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:849415)
at RuntimeDriver.acquireConnection (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:814312)
at async DefaultConnectionProvider.provideConnection (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/runtime.mjs:1:812940)
at async Object.fn (file:///Users/evan/Code/pinlog/.wrangler/tmp/pages-RBmLxW/chunks/build/index-CvHsH36j.mjs:1:18140)
at null.<anonymous> (async file:///Users/evan/Code/pinlog/.wrangler/tmp/dev-6mfei5/a8mn73yuqfn.js:40924:82)
Ping for toast
Ping for toast5mo ago
GitHub
If the connection to PG fails during execution, it will cause the p...
Env: Win10 Node v20.14.0 kysely: 0.27.3 kysely-postgres-js: 2.0.0, postgres: 3.4.4 Reproduction steps: Start the PostgreSQL service. Start the application. Kill the PostgreSQL process. The error re...
Ping for toast
Ping for toast5mo ago
progres, get it? that made it work in wrangler dev but not production still in production, every request is causing an infinite loop that eats my CPU time (went from 18k ms to 100k in a couple hours) yeah I'm really struggling here, my hyperdrive config ID is 5470ba839d3c47d7a9de80ebf5ee2bab I assume there is some issue connecting to the database
Ping for toast
Ping for toast5mo ago
possibly related to this that I saw in dev
No description
elithrar
elithrar5mo ago
Can you confirm what version of Postgres.js you have installed? What does your package-lock.json say?
Ping for toast
Ping for toast5mo ago
3.4.4
elithrar
elithrar5mo ago
Role “Postgres” does not exist implies you don’t have a user set up on your remote server called “Postgres”
elithrar
elithrar5mo ago
No description
Ping for toast
Ping for toast5mo ago
Right, except this was in development and my connection string was
[[hyperdrive]]
localConnectionString = "postgresql://pf:pf@localhost:5432/pinefore"
[[hyperdrive]]
localConnectionString = "postgresql://pf:pf@localhost:5432/pinefore"
but creating the user fixed it in development in production, it just... hangs
elithrar
elithrar5mo ago
Can you open a GitHub issue with your code + command line invocations, as well as your Hyperdrive config ID?
Ping for toast
Ping for toast5mo ago
to what repository?
elithrar
elithrar5mo ago
This is the first report like this and easier to understand if we can reproduce
Ping for toast
Ping for toast5mo ago
workers-sdk?
elithrar
elithrar5mo ago
Yes
Ping for toast
Ping for toast5mo ago
sounds great
Ping for toast
Ping for toast5mo ago
GitHub
🐛 BUG: Obscure hangs while using hyperdrive and postgres.js · Issue...
Which Cloudflare product(s) does this pertain to? Pages, Other What version(s) of the tool(s) are you using? Wrangler 3.62.0, Postgres.js 3.4.4 What version of Node are you using? No response What ...
Ping for toast
Ping for toast5mo ago
Ok I might have something, I tried connecting to the production database locally via miniflare instead of a local database, and it says "invalid url" despite the fact that psql accepts it, due to the special characters
No description
Ping for toast
Ping for toast5mo ago
I'm trying 1. to connect to the database via workers without hyperdrive 2. changing the password
Ping for toast
Ping for toast5mo ago
ok so I've gotten it working without hyperdrive
No description
Ping for toast
Ping for toast5mo ago
lets swap in hyperdrive
Ping for toast
Ping for toast5mo ago
and now look at it!
No description
Ping for toast
Ping for toast5mo ago
(I made sure to update the password for hyperdrive)
Ping for toast
Ping for toast5mo ago
No description
AJR
AJR5mo ago
I'm not familiar with your editor, sorry if this is a dumb question. Is this attempting to connect through a worker? Hyperdrive is only accessible via a binding. I'm reading through your GH issue now, one sec You seeing any errors in your Hetzner log? If you could add a slightly broader code snippet to your GH issue, that'd be helpful. It's not clear to me how you're populating connectionString in that example, and that is central to this effort. As an aside, I recognize this is frustrating and I appreciate you spending the effort to document this and work through it.
Ping for toast
Ping for toast5mo ago
this is a cloudflare pages deployment, hyperdrive is bound to it inside the wrangler.toml I will check hetzner for logs, I did that before and I saw a random chinese IP doing nonsense, and I thought "this probably isn't cloudflare", and that was it. I'll give it a look
AJR
AJR5mo ago
Hyperdrive egresses through the untrusted Warp IP address space. It's a fluid pool, won't be "recognized" Cloudflare addresses
Ping for toast
Ping for toast5mo ago
in any case, it was making 2 requests per second and it wasn't using SSL so
AJR
AJR5mo ago
Then it's probably not us, yeah
Ping for toast
Ping for toast5mo ago
nothing interesting
No description
Ping for toast
Ping for toast5mo ago
Connection string is being populated like
dbCache = db(
env.CONNECTION_STRING ||
env.HYPERDRIVE.connectionString
);
dbCache = db(
env.CONNECTION_STRING ||
env.HYPERDRIVE.connectionString
);
The reason for this is just so I could test swapping out the connection string to be a direct connection, I eventually did get to work. Env is being populated like
return client
.decorate({ env: event.nativeEvent.context?.cloudflare?.env })
.fetch(request);
return client
.decorate({ env: event.nativeEvent.context?.cloudflare?.env })
.fetch(request);
, I know this looks "not cloudflaree", just working with what I got unfortunately, but I've managed to successfully log the connection string at one point postgresql://xx:[email protected]:5432/xxxxxxxxx?sslmode=disable
AJR
AJR5mo ago
Yeah, it'll be internal, and gibberish for your purposes. Ok, that all looks right to me so far.
Ping for toast
Ping for toast5mo ago
(right now I am trying to get the request to timeout again for Real-time Logs but its refusing... just going on and on)
Ping for toast
Ping for toast5mo ago
yup
No description
AJR
AJR5mo ago
To be clear, you're trying to run local dev to a remote database here? I know that is a use case that we've fought with a bit. Just want to confirm as I dig
Ping for toast
Ping for toast5mo ago
No, I've gotten that working correctly (though I've encountered a lot of issues getting to that point). Right now, the only thing that "isn't working" is the deployed worker, connecting to the database via hyperdrive
AJR
AJR5mo ago
Looks like this config has an IP address registered as origin
Ping for toast
Ping for toast5mo ago
yes it does is that the cause?
AJR
AJR5mo ago
Can you try making one using a hostname? There's enough moving parts here that I'm not 100% sure, but we definitely recommend using hostnames
Ping for toast
Ping for toast5mo ago
sure, what is the recommended method? an A record?
AJR
AJR5mo ago
Going to vary based on your provider. I know I've seen Hetzner databases configured with hostnames, and they (mostly) all worked fine, but I'd need to look into their docs to see how they prefer you to do it. (you're on Hetzner, right? I think I read that somewhere in here?)
Ping for toast
Ping for toast5mo ago
Yes I am, A records are reccomended I believe. I've made one, I will update the config and redeploy the worker I think that was it!!!!!!!!
Ping for toast
Ping for toast5mo ago
No description
AJR
AJR5mo ago
Victory! I'll see to it that this is made more clear in our docs. Happy hunting.
Ping for toast
Ping for toast5mo ago
Thank you so much!! Definitely a couple other notes: 1. At least miniflare doesn't support special characters as a password, it needs to be A-z0-9, maybe a couple others, despite the fact postgres supports it 2. I don't know how much control you have over postgres.js but this hang on a failed connection is really really really annoying 3. It would be helpful if hyperdrive logs could be exposed somehow to get better visibility into the cause of these failures but for now I'm just happy to have it working
AJR
AJR5mo ago
This is good feedback, thank you! CC @thomasgauvin
Ping for toast
Ping for toast5mo ago
Cheers!
Ping for toast
Ping for toast5mo ago
yeah the docs currently say IPs are supported
No description
AJR
AJR5mo ago
Some providers play nicer on that front than others. I didn't know Hetzner in particular presented this challenge until today, just had a suspicion. Docs are going to need some tweaking here, for sure.
Ping for toast
Ping for toast5mo ago
Out of curiosity, what is the root cause?
AJR
AJR5mo ago
I still don't know for sure. We can egress to IP addresses across most of our stack. I'm more of a DB internals guy than a networking guy, so I hesitate to venture guesses.
Ping for toast
Ping for toast5mo ago
Got it, well thank you regardless!
Want results from more Discord servers?
Add your server