Hi there. Sorry in advance for the noob
Hi there. Sorry in advance for the noob question.
Does binding values have to be unique when using the Wrangler CLI /
wrangler.toml
config?
E.G: if I have multiple environments, that I want to connect to different D1 databases.
I'm a bit confused since in the dashboard it seems like you create 1 binding per 1 database, but when using the wrangler.toml
config file and the CLI, the binding name seems to be used more like an environment variable that you can then use in your worker.
Would the following 2 environments point to 2 different databases even though the binding names are the same?
3 Replies
From the documentation it seems like the binding names also have to be unique.
Here is the example:
But then how would I access the different binding variables in my worker, depending on the environment, since they are now different
Here is my worker.ts file (using hono with trpc)
So the bindings in my example above [env.staging] and [env.production] can just be "DB" but then if the database_name and database_id are different they will point to different databases?
If so, then the binding name is solely used as an environment variable (and not actually used as a reference to point to specific databases)
effectively used like an environment variable, yeah
Cool, thank you for the quick response both of you!
When deploying, would the bindings then show up in the dashboard as well?
Thank you!