Three questions about Hyperdrive

I’m connecting to a Postgres DB via Hyperdrive and node-postgres and have three questions:

  1. For local dev, Wrangler tells me to put the connection string to my DB directly in the TOML file. The problem with this is my dev DB is remote, not on my local machine, so this would mean committing DB credentials to my repo. Is there any way round this? I’ve tried putting the connection string in .dev.vars instead but Wrangler errors that it wants it in the TOML file only.

  2. The Hyperdrive tutorial (https://developers.cloudflare.com/hyperdrive/get-started) discusses setting up HD for local dev, but doesn’t say how to configure the connection string for production use and where this should be stored. Should it be a secret, and what would the JS code look like? Does this secret auto-populate my env.hyperdrive.connectionString var?

  3. I’ve asked this three times on the Discord but so far no joy. I read somewhere that one benefit of Hyperdrive is it handles pooling for you. Does this mean that I can forget about generating/managing pools manually in my JS, and just leave that to Hyperdrive? i.e. I can just use client.query() rather than pool.query() , or am I wrong here?

Thank you.

I have subsequently found the answers to questions 1 and 3 on Discord so I’ll put them here for future users who find this question:

1. There seems to be no way round this currently. @rozenmd has asked me to file a feature request on this, which I have done (https://github.com/cloudflare/workers-sdk/issues/4578).

3. Yes - you can ignore managing pools within code. Workers live only for a short time, so any manually-created pools wouldn’t live longer than the worker anyway.

2 Likes

For 2, as per the tutorial you wrangler hyperdrive create and then you create the binding in your wrangler.toml, and then you can use env.<binding>.connectionString

Sorry I’m still a little unclear. For dev use it says set connectionString manually in the TOML. So that points to my dev DB. But for prod use, are you saying the connectionString var in the TOML is ignored, and instead a variable of the same name is populated by the secret, which points to my prod DB?