Skip to content

Commit 5d5ad91

Browse files
committed
Adding a note about local / remote development.
1 parent 00a1682 commit 5d5ad91

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ A Durable Object fully ceases to exist if, when it shuts down, its storage is em
6767

6868
However if you ever write using [Storage API](/durable-objects/api/storage-api/), including setting alarms, then you must explicitly call [`storage.deleteAll()`](/durable-objects/api/storage-api/#deleteall) to empty storage. It is not sufficient to simply delete the specific data that you wrote, such as deleting a key or dropping a table, as some metadata may remain. The only way to remove all storage is to call `deleteAll()`. Calling `deleteAll()` ensures that a Durable Object will not be billed for storage.
6969

70+
```ts
71+
export class MyDurableObject extends DurableObject<Env> {
72+
73+
constructor(ctx: DurableObjectState, env: Env) {
74+
super(ctx, env);
75+
}
76+
77+
async clearDo():Promise<void> {
78+
// Clears the Durable Object storage
79+
// This will delete all the storage associated with this Durable Object instance
80+
// This will also delete the Durable Object instance itself
81+
await this.ctx.storage.deleteAll();
82+
}
83+
}
84+
```
85+
7086
## SQL API Examples
7187

7288
<Render file="durable-objects-sql" />

src/content/docs/durable-objects/reference/environments.mdx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ sidebar:
88

99
import { WranglerConfig } from "~/components";
1010

11+
Environments provide isolated spaces where your code runs with specific dependencies and configurations. This can be useful for a number of reasons, such as compatibility testing or version management. Using different environments can help with code consistency, testing, and production segregation, which reduces the risk of errors when deploying code.
12+
13+
## Wrangler environments
14+
1115
[Wrangler](/workers/wrangler/install-and-update/) allows you to deploy the same Worker application with different configuration for each [environment](/workers/wrangler/environments/).
1216

1317
If you are using Wrangler environments, you must specify any [Durable Object bindings](/workers/runtime-apis/bindings/) you wish to use on a per-environment basis.
@@ -56,3 +60,25 @@ durable_objects.bindings = [
5660
```
5761

5862
</WranglerConfig>
63+
64+
## Local development
65+
66+
Local development sessions create a standalone, local-only environment that mirrors the production environment, so that you can test your Worker and Durable Objects before you deploy to production.
67+
68+
An existing Durable Object binding of DB would be available to your Worker when running locally.
69+
70+
Refer to Workers [Local development](/workers/local-development/#supported-resource-bindings-in-different-environments).
71+
72+
## Remote development
73+
74+
KV-backed Durable Objects support remote development using the dashboard playground. The dashboard playground uses a browser version of Visual Studio Code, allowing you to rapidly iterate on your Worker entirely in your browser.
75+
76+
To start remote development:
77+
78+
1. Log in to your Cloudflare dashboard, and go to [**Workers & Pages** > **Overview**](https://dash.cloudflare.com/?to=/:account/workers-and-pages).
79+
2. Select an existing Worker.
80+
3. Select the **Edit code** icon located on the upper-right of the screen.
81+
82+
:::caution
83+
Remote development is only available for KV-backed Durable Objects. SQLite-backed Durable Objects do not support remote development.
84+
:::

src/content/docs/workers/local-development.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,28 @@ npx wrangler dev
3838
| Analytics Engine |||
3939
| Browser Rendering |||
4040
| D1 |||
41-
| Durable Objects || |
41+
| Durable Objects ||[^2] |
4242
| Email Bindings |||
43-
| Hyperdrive |[^2] ||
43+
| Hyperdrive |[^3] ||
4444
| Images |||
4545
| KV |||
4646
| mTLS |||
4747
| Queues |||
4848
| R2 |||
4949
| Rate Limiting |||
5050
| Service Bindings (multiple workers) |||
51-
| Vectorize |[^3] ||
51+
| Vectorize |[^4] ||
5252
| Workflows |||
5353

5454
With any bindings that are not supported locally, you will need to use the [`--remote` command](#develop-using-remote-resources-and-bindings) in wrangler, such as `wrangler dev --remote`.
5555

5656
[^1]: Using Workers AI always accesses your Cloudflare account in order to run AI models and will incur usage charges even in local development.
5757

58-
[^2]: Using Hyperdrive with local development allows you to connect to a local database (running on `localhost`) but you cannot connect to a remote database. To connect to a remote database, use remote development.
58+
[^2]: For KV-backed Durable Objects only. SQLite-backed Durable Objects do not support remote development.
5959

60-
[^3]: Using Vectorize always accesses your Cloudflare account to run queries, and will incur usage charges even in local development.
60+
[^3]: Using Hyperdrive with local development allows you to connect to a local database (running on `localhost`) but you cannot connect to a remote database. To connect to a remote database, use remote development.
61+
62+
[^4]: Using Vectorize always accesses your Cloudflare account to run queries, and will incur usage charges even in local development.
6163

6264
## Work with local data
6365

0 commit comments

Comments
 (0)