From ce1a0e30f9e5c38f144089550ab15fa751d8e666 Mon Sep 17 00:00:00 2001 From: Vy Ton Date: Tue, 1 Oct 2024 16:07:37 -0400 Subject: [PATCH] SQLite in DO clarifications: - deleteAll() behavior - multi-statement queries with sql.exec --- src/content/docs/durable-objects/api/storage-api.mdx | 6 ++++-- .../best-practices/access-durable-objects-storage.mdx | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/content/docs/durable-objects/api/storage-api.mdx b/src/content/docs/durable-objects/api/storage-api.mdx index b9b791737b9529e..fe6b422f5720db7 100644 --- a/src/content/docs/durable-objects/api/storage-api.mdx +++ b/src/content/docs/durable-objects/api/storage-api.mdx @@ -100,7 +100,9 @@ Each method is implicitly wrapped inside a transaction, such that its results ar * deleteAll(options ): - * Deletes all keys and associated values, effectively deallocating all storage used by the Durable Object. In the event of a failure while the `deleteAll()` operation is still in flight, it may be that only a subset of the data is properly deleted. `deleteAll()` does not proactively delete [Alarms](/durable-objects/api/alarms/). Use [`deleteAlarm()`](/durable-objects/api/alarms/#deletealarm) to delete an alarm. + * Deletes all stored data, effectively deallocating all storage used by the Durable Object. For Durable Objects with a key-value storage backend, `deleteAll()` removes all keys and associated values for an individual Durable Object. For Durable Objects with a [SQLite storage backend](/durable-objects/best-practices/access-durable-objects-storage/#sqlite-storage-backend), `deleteAll()` removes the entire contents of a Durable Object's private SQLite database. + * In the event of a failure while the `deleteAll()` operation is still in flight, it may be that only a subset of the data is properly deleted. + * `deleteAll()` does not proactively delete [Alarms](/durable-objects/api/alarms/). Use [`deleteAlarm()`](/durable-objects/api/alarms/#deletealarm) to delete an alarm. #### Supported options @@ -245,7 +247,7 @@ SQL API methods accessed with `ctx.storage.sql` are only allowed on [Durable Obj #### Parameters * `query`: - * The SQL query string to be executed. `query` can contain `?` placeholders for parameter bindings. + * The SQL query string to be executed. `query` can contain `?` placeholders for parameter bindings. Multiple SQL statements, separated with a semicolen, can be executed in the `query`; any parameter bindings are applied to the last SQL statement in the `query`. * `bindings`: * Optional variable number of arguments that correspond to the `?` placeholders in `query`. diff --git a/src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx b/src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx index 0dc945c0e2ca58a..bd0c082f3736e15 100644 --- a/src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx +++ b/src/content/docs/durable-objects/best-practices/access-durable-objects-storage.mdx @@ -41,6 +41,9 @@ export class Counter extends DurableObject { } } ``` +### Removing a Durable Object's storage + +To effectively "delete" a Durable Object, you should first use [`deleteAll()`](/durable-objects/api/storage-api/#deleteall) to remove any attached storage for a Durable Object. Calling `deleteAll()` ensures that a Durable Object will not be [billed for Storage API usage](/durable-objects/platform/pricing/#storage-api-billing). Once storage is delete and a Durable Objecy is no longer active due to incoming requests, then the Durable Object is effectively deleted. ## SQLite storage backend