Demonstrates std.storage.kv (key-value) and std.storage.doc (document) modules. The same code works identically on browser, Node.js, Deno, and WASI.
| File | Description |
|---|---|
cross-platform-storage.cov |
Key-value and document storage patterns |
| Platform | Key-Value | Document |
|---|---|---|
| Deno | Deno KV | Deno KV |
| Browser | localStorage | IndexedDB |
| Node.js | Files | SQLite |
| WASI | Preopened dir | Embedded DB |
Simple string key-value pairs with effect std.storage:
effects
effect std.storage
end
body
step id="s1" kind="call"
fn="std.storage.kv.set"
arg name="key" lit="user:theme"
arg name="value" lit="dark"
as="_"
end
step id="s2" kind="call"
fn="std.storage.kv.get"
arg name="key" lit="user:theme"
as="theme"
end
end
Query documents using target="std.storage":
step id="s1" kind="query"
target="std.storage"
select all
from="users"
where
and
equals field="status" lit="active"
greater field="age" var="min_age"
end
end
order by="created_at" dir="desc"
limit=50
as="users"
end
Use std.storage.doc.* functions for CRUD operations:
step id="s1" kind="call"
fn="std.storage.doc.put"
arg name="collection" lit="users"
arg name="id" from="user_id"
arg name="data" from="user_data"
as="doc"
end
Optimize queries by creating indexes on frequently queried fields:
step id="s1" kind="call"
fn="std.storage.doc.create_index"
arg name="collection" lit="users"
arg name="field" lit="status"
as="_"
end