Local development
Hyperdrive can be used when developing and testing your Workers locally by connecting to any local database instance running on your machine directly. Local development uses Wrangler, the command-line interface for Workers, to manage local development sessions and state.
To specify a database to connect to when developing locally, you can:
- Recommended Create a
WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>
environmental variable with the connection string of your database.<BINDING_NAME>
is the name of the binding assigned to your Hyperdrive in yourwrangler.toml
or Pages configuration. This allows you to avoid committing potentially sensitive credentials to source control in yourwrangler.toml
, if your test/development database is not ephemeral. If you have configured multiple Hyperdrive bindings, replace<BINDING_NAME>
with the unique binding name for each. - Set
localConnectionString
inwrangler.toml
.
If both the WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>
environmental variable and localConnectionString
in wrangler.toml
are set, wrangler dev
will use the environmental variable instead. Use unset WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>
to unset any existing environmental variables.
For example, to use the environmental variable, export the environmental variable before running wrangler dev
:
To configure a localConnectionString
in wrangler.toml
, ensure your Hyperdrive bindings have a localConnectionString
property set:
The following example shows you how to check your wrangler version, set a WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_TEST_DB
environmental variable, and run a wrangler dev
session:
wrangler dev
separates local and production (remote) data. A local session does not have access to your production data by default. To access your production (remote) Hyperdrive configuration, pass the --remote
flag when calling wrangler dev
. Any changes you make when running in --remote
mode cannot be undone.
Refer to the wrangler dev
documentation to learn more about how to configure a local development session.
- Use
wrangler dev
to run your Worker and Hyperdrive locally and debug issues before deploying. - Learn how Hyperdrive works.
- Understand how to configure query caching in Hyperdrive.