Skip to content

Commit 2e3ebd4

Browse files
committed
[Durable Objects] Document transaction API changes with SQLite.
1 parent 644f72f commit 2e3ebd4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/content/docs/durable-objects/api/storage-api.mdx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,21 @@ The `put()` method returns a `Promise`, but most applications can discard this p
191191

192192
* `txn`
193193

194-
* Provides access to the `put()`, `get()`, `delete()` and `list()` methods documented above to run in the current transaction context. In order to get transactional behavior within a transaction closure, you must call the methods on the `txn` Object instead of on the top-level `state.storage` Object.<br/><br/>Also supports a `rollback()` function that ensures any changes made during the transaction will be rolled back rather than committed. After `rollback()` is called, any subsequent operations on the `txn` Object will fail with an exception. `rollback()` takes no parameters and returns nothing to the caller.
194+
* Provides access to the `put()`, `get()`, `delete()` and `list()` methods documented above to run in the current transaction context. In order to get transactional behavior within a transaction closure, you must call the methods on the `txn` Object instead of on the top-level `ctx.storage` Object.<br/><br/>Also supports a `rollback()` function that ensures any changes made during the transaction will be rolled back rather than committed. After `rollback()` is called, any subsequent operations on the `txn` Object will fail with an exception. `rollback()` takes no parameters and returns nothing to the caller.
195+
196+
* When using [the SQLite-backed storage engine](/durable-objects/reference/durable-objects-migrations/#enable-sqlite-storage-backend-on-create-durable-object-class-migration), the `txn` object is obsolete. Any storage operations performed directly on the `ctx.storage` object, including SQL queries using [`ctx.storage.sql.exec()`](#sqlexec), will be considered part of the transaction.
197+
198+
### transactionSync
199+
200+
* `transactionSync(callback)`: <Type text='any' />
201+
202+
* Only available when using [the SQLite-backed storage engine](/durable-objects/reference/durable-objects-migrations/#enable-sqlite-storage-backend-on-create-durable-object-class-migration).
203+
204+
* Invokes `callback()` wrapped in a transaction, and returns its result.
205+
206+
* If `callback()` throws an exception, the transaction will be rolled back.
207+
208+
* The callback must complete synchronously, i.e. it should not be declared `async` nor otherwise return a Promise. Only synchronous storage operations can be part of the transaction. This is intended for use with SQL queries using [`ctx.storage.sql.exec()`](#sqlexec), which complete sychronously.
195209

196210
### sync
197211

0 commit comments

Comments
 (0)