skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
danmossa/spacetimedb-skills71 installs

spacetimedb-reducers

Use when writing SpacetimeDB reducers, lifecycle reducers, scheduled reducers, reducer context code, table mutations, indexed lookups, reducer isolation logic, or reducer error handling. Triggers on: reducer, ReducerContext, ctx, sender, client_connected, client_disconnected, init, scheduled reducer, insert row, delete row, update row.

How do I install this agent skill?

npx skills add https://github.com/danmossa/spacetimedb-skills --skill spacetimedb-reducers
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    The skill provides comprehensive documentation and coding patterns for writing SpacetimeDB reducers in multiple languages. No security issues were detected, and the content promotes security best practices.

  • Socketpass

    No alerts

  • Snykpass

    Risk: LOW · No issues

What does this agent skill do?

Use this skill for reducer implementation and transactional server logic.

Core reducer patterns

Reducers are the transactional entrypoints for table mutation. A successful reducer commits all table changes; a thrown exception, returned error, or panic rolls all of them back.

TypeScript reducer shape:

export const create_user = spacetimedb.reducer(
  { name: t.string(), email: t.string() },
  (ctx, { name, email }) => {
    if (name === "") throw new Error("Name cannot be empty");
    ctx.db.user.insert({ id: 0n, name, email });
  },
);

Language-specific signatures:

  • TypeScript: spacetimedb.reducer(args, (ctx, args) => { ... }), or spacetimedb.reducer((ctx) => { ... }) for no args.
  • C#: [SpacetimeDB.Reducer] public static void Name(ReducerContext ctx, ...).
  • Rust: #[spacetimedb::reducer] pub fn name(ctx: &ReducerContext, ...) -> Result<(), String>; import spacetimedb::Table for table methods.
  • Lifecycle reducers use init, client_connected, and client_disconnected variants in the language's syntax.

Table access

  • Insert rows through the generated table handle; use the trigger value (0, 0n, etc.) for auto-increment fields.
  • Find one row through a primary key or unique index: TypeScript ctx.db.user.id.find(id), C# ctx.Db.User.Id.Find(id), Rust ctx.db.user().id().find(id).
  • Filter many rows through indexed columns. Avoid full iter() scans on hot paths unless the table is known to be small.
  • Update by finding a row, modifying it, then calling the update method on the same primary-key index.
  • Delete by primary key/unique value or indexed filters when possible.
  • Use ctx.sender in TypeScript/C# and ctx.sender() in Rust/C++ for the caller identity on SpacetimeDB 2.0.

Transaction guidance

  • Keep reducers short and deterministic; move external I/O to procedures.
  • Nested reducer calls share the same transaction; they are not separate commits.
  • Use sender-facing errors for expected validation failures when the language exposes them; reserve panics or unchecked exceptions for programmer errors.
  • Scheduled reducers run from schedule-table rows and may have no client sender.

Reference map

NeedOpen
Reducer basics and table accessreferences/functions-reducers.md
Lifecycle reducersreferences/functions-reducers-lifecycle.md
Reducer contextreferences/functions-reducers-reducer-context.md
Error handlingreferences/functions-reducers-error-handling.md
Function categoriesreferences/functions.md

Guidance

  • Treat reducers as transactions: keep side effects and error behavior aligned with the reference semantics.
  • Use ctx.sender/ctx.sender() according to the project's SpacetimeDB version; load spacetimedb-upgrade for 1.0 to 2.0 migrations.
  • Route schema questions to spacetimedb-tables.

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/danmossa/spacetimedb-skills/spacetimedb-reducers">View spacetimedb-reducers on skillZs</a>