RawtohRawtoh/Docs
Documentation

Storage

A persistent key-value store for your automation scripts.

Storage is a persistent key-value store scoped to your organization. Your scripts can use it to remember data between executions.

What is it?

Each organization has its own storage — a simple key-value database where keys are strings and values are arbitrary JSON. Storage persists across all script executions, making it perfect for:

Using storage in scripts

Inside your action code, import storage from "rawtoh":

Read a value

import { storage } from "rawtoh"

const count = await storage.get("sub_count")
// Returns the stored value, or undefined if the key doesn't exist

Write a value

import { storage } from "rawtoh"

await storage.set("sub_count", 42)
await storage.set("last_user", { name: "alice", time: Date.now() })
// Values can be any JSON-serializable data

Update a value atomically

Two actions can run at the same time — two chat messages a few milliseconds apart, for instance. A get followed by a set would let one overwrite the other. storage.update() applies your function to the current value and writes the result only if nobody else wrote in between, retrying otherwise. It returns the value that was written.

import { storage } from "rawtoh"

// Read-modify-write in one step. The function receives the current value
// (undefined if the key does not exist) and returns the new one.
const count = await storage.update("sub_count", (n) => (n ?? 0) + 1)

await storage.update("seen_users", (list) => [...(list ?? []), "alice"])

The function must be synchronous and side-effect free: it may be replayed on a write conflict. Don't await or call modules inside it.

Practical example

import { event, module, storage } from "rawtoh"

// Track how many times each user has used a command
const user = event.payload.username
const key = `cmd_count:${user}`

const count = await storage.update(key, (n) => (n ?? 0) + 1)

await module("twitch").request("chat.say", {
  message: `@${user}, you've used this command ${count} times!`
})

Managing storage in the UI

You can also view and edit storage entries directly from the dashboard. Go to the Storage page in the sidebar to:

This is useful for setting up initial configuration, debugging script state, or manually adjusting values.

Tips