this.ctx.storage (an ActorStorage) is the actor’s per-key persistent storage. A turn that returns successfully is persisted — all writes made during the turn (put/delete/transaction/sql.exec/setAlarm) commit atomically at end-of-turn; a turn that throws commits nothing.
- Lazy per
get— state is not preloaded on activation. Callgetwhen you need it. - Read-your-writes — reads always reflect prior writes from the same actor.
- Per-actor method serialization — calls to one actor instance are dispatched one at a time, giving you effective ACID at the actor level.
- Values round-trip through a codec. JSON natives plus
Date,Map,Set, typed arrays,ArrayBuffer,BigInt, andRegExpcome back as what you stored. Unstorable values — functions, class instances, circular structures, promises, streams — are rejected with aCodecErrorat the write. - Keys starting with
__telnyx_are reserved for the runtime’s own bookkeeping — writes to them are rejected.
list(options)
Lexicographic key order; reverse: true flips it. Returns a Map<string, T> to preserve ordering.
transaction(fn)
Atomic batch. fn receives a StorageTransaction with the same get/put/delete/list surface.
fn throws, the buffered writes are discarded — and the enclosing method call
fails with ActorOutputGateError, even if your code catches the rejection. Only the
transaction’s own writes are undone: writes you make after catching the rejection still
commit, but the caller sees the error instead of your return value. A thrown transaction
is not a control-flow tool for “try the write, continue on failure”.
sql
ctx.storage.sql is a private embedded SQLite database for this actor — a separate,
synchronous store beside the key/value surface above. See
SQL storage for the exec /
cursor contract, types, transactions, limits, and durability.
transactionSync(fn)
Atomic SQL transaction: runs fn synchronously, commits its sql.exec writes when it
returns (passing the return value through), rolls all of them back if it throws. fn must
not be async — an async callback throws SqlAsyncTransactionError and commits nothing.
This is the only transaction API for SQL: exec() rejects raw BEGIN / COMMIT /
ROLLBACK / SAVEPOINT with SqlTransactionControlError. Unlike a thrown
transaction(fn), a thrown transactionSync does not poison the
turn: catch it and the method call completes normally.
Related
- Key-Value storage — the
get/put/listguide - SQL storage — the
ctx.storage.sqlguide - Actor Context —
ctx.storagelives here - Alarms — the
setAlarm/getAlarm/deleteAlarmcontract