douglance/spacetimedb/spacetimedb-rust
Claude Code and agent skill by douglance/spacetimedb
- community
Checking that the SKILL.md file is still in the repository.
Develop SpacetimeDB server modules in Rust. Use when writing reducers, tables, or module logic.
Install
npx vskill@latest install douglance/spacetimedb/spacetimedb-rustSKILL.md
SpacetimeDB Rust Module Development
SpacetimeDB modules are WebAssembly applications that run inside the database. They define tables to store data and reducers to modify data. Clients connect directly to the database and execute application logic inside it.
Tested with: SpacetimeDB runtime 1.11.x,spacetimedbcrate 1.1.x
HALLUCINATED APIs — DO NOT USE
These APIs DO NOT EXIST. LLMs frequently hallucinate them.
CORRECT PATTERNS:
DO NOT:
- Derive `SpacetimeType` on `#[table]` structs — the macro handles this
- Use mutable context —
&ReducerContext, not&mut ReducerContext - Forget `Table` trait import — required for table operations
- Use field access for tables —
ctx.db.player()notctx.db.player
Common Mistakes Table
Server-side errors
| Wrong | Right | Error | |
|---|---|---|---|
#[derive(SpacetimeType)] on #[table] | Remove it — macro handles this | Conflicting derive macros | |
ctx.db.player (field access) | ctx.db.player() (method) | "no field player on type" | |
ctx.db.player().find(id) | ctx.db.player().id().find(&id) | Must access via index | |
&mut ReducerContext | &ReducerContext | Wrong context type | |
Missing use spacetimedb::Table; | Add import | "no method named insert" | |
#[table(name = "my_table")] | #[table(name = my_table)] | String literals not allowed | |
Missing public on table | Add public flag | Clients can't subscribe | |
#[spacetimedb::reducer] | #[reducer] after import | Wrong attribute path | |
| Network/filesystem in reducer | Use procedures instead | Sandbox violation | |
| Panic for expected errors | Return Result<(), String> | WASM instance destroyed |
Client-side errors
| Wrong | Right | Error | |
|---|---|---|---|
| Wrong crate name | spacetimedb-sdk | Dependency not found | |
| Manual event loop | Use tokio runtime | Async issues |
Hard Requirements
- DO NOT derive `SpacetimeType` on `#[table]` structs — the macro handles this
- Import `Table` trait — required for all table operations
- Use `&ReducerContext` — not
&mut ReducerContext - Tables are methods —
ctx.db.table()notctx.db.table - Reducers must be deterministic — no filesystem, network, timers, or external RNG
- Use `ctx.random()` or `ctx.rng` — not
randcrate for random numbers - Add `public` flag — if clients need to subscribe to a table
Project Setup
Cargo.toml Requirements
The crate-type = ["cdylib"] is required for WebAssembly compilation.
Essential Imports
Additional imports as needed:
Table Definitions
Tables store data in SpacetimeDB. Define tables using the #[spacetimedb::table] macro on a struct.
Basic Table
Table Attributes
| Attribute | Description | |
|---|---|---|
name = identifier | Required. The table name used in ctx.db.{name}() | |
public | Makes table visible to clients via subscriptions | |
scheduled(reducer_name) | Creates a schedule table that triggers the named reducer | |
index(name = idx, btree(columns = [a, b])) | Creates a multi-column index |
Column Attributes
| Attribute | Description | |
|---|---|---|
#[primary_key] | Unique identifier for the row (one per table max) | |
#[unique] | Enforces uniqueness, enables find() method | |
#[auto_inc] | Auto-generates unique integer values when inserting 0 | |
#[index(btree)] | Creates a B-tree index for efficient lookups | |
#[default(value)] | Default value for migrations (must be const-evaluable) |
Supported Column Types
Primitives: u8, u16, u32, u64, u128, u256, i8, i16, i32, i64, i128, i256, f32, f64, bool, String
SpacetimeDB Types: Identity, ConnectionId, Timestamp, Uuid, ScheduleAt
Collections: Vec<T>, Option<T>, Result<T, E> where inner types are also supported
Custom Types: Any struct/enum with #[derive(SpacetimeType)]
Insert Returns the Row
Data Visibility and Row-Level Security
`public` flag exposes ALL rows to ALL clients.
| Scenario | Pattern | |
|---|---|---|
| Everyone sees all rows | #[table(name = x, public)] | |
| Users see only their data | Private table + row-level security |
Private Table (default)
Row-Level Security (RLS)
Use RLS to filter which rows each client can see:
With RLS, clients can subscribe to the table but only see rows where the filter returns true for their identity.
Reducers
Reducers are transactional functions that modify database state. They run inside the database and are the only way to mutate tables.
Basic Reducer
Reducer Rules
- First parameter must be
&ReducerContext - Additional parameters must implement
SpacetimeType - Return
(),Result<(), String>, orResult<(), E>whereE: Display - All changes roll back on panic or
Errreturn - Reducers run in isolation from concurrent reducers
- Cannot make network requests or access filesystem
- Must import
Tabletrait for table operations:use spacetimedb::Table;
ReducerContext
The ReducerContext provides access to the database and caller information.
Properties
Table Operations
Insert
Find by Unique/Primary Key
Filter by Indexed Column
Update
Updates require a unique column. Find the row, modify it, then call update():
Delete
Iterate All Rows
Indexes
Single-Column Index
Multi-Column Index
Querying Multi-Column Indexes
Identity and Authentication
Storing User Identity
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/spacetimedb-rust/SKILL.md
Popularity
- 7-day trend score
- 0
Refreshed 27 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/douglance/spacetimedb/spacetimedb-rust)