csharp-server

Write SpacetimeDB server modules in C# with tables, reducers, views, and HTTP handlers.

25.1k|1.1k|Updated Jun 17, 2023
One-click install
npx skills add https://github.com/clockworklabs/SpacetimeDB --skill csharp-server
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: csharp-server
Source: https://github.com/clockworklabs/SpacetimeDB/tree/main/codex-plugin/plugins/spacetimedb/skills/csharp-server
Command: npx skills add https://github.com/clockworklabs/SpacetimeDB --skill csharp-server

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing SpacetimeDB server modules in C# requires precise knowledge of SDK attributes, context APIs, and code-generation conventions; mistakes in attribute usage or context handling cause compile errors or runtime failures. This reference provides the exact patterns for defining tables, reducers, indexes, views, scheduled tasks, and HTTP endpoints in C# modules.

Core Features & Use Cases

  • Table and Reducer Definitions: Declare tables with [SpacetimeDB.Table], column attributes like [PrimaryKey], [AutoInc], [Unique], and BTree indexes, plus reducers as public static methods receiving ReducerContext.
  • Views, Scheduling, and HTTP: Implement anonymous and per-user views, scheduled tables with ScheduleAt timers, procedures with outbound HTTP via ctx.Http, and inbound HTTP routers with [SpacetimeDB.HttpHandler].
  • Use Case: A developer building a multiplayer game backend needs a score table with an auto-increment primary key, an AddRecord reducer that stamps the caller's identity, and a scheduled tick reducer firing every five seconds; this reference supplies the exact C# syntax for each piece.

Quick Start

Use the csharp-server skill to write a SpacetimeDB C# module with a public table and a reducer that inserts a row owned by the caller.

Frequently Asked Questions about csharp-server

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a table in a SpacetimeDB C# module?

Define a table by applying [SpacetimeDB.Table] to a public partial struct with an Accessor name. Add column attributes like [PrimaryKey], [AutoInc], [Unique], or [SpacetimeDB.Index.BTree], then access it through ctx.Db using the accessor name.

How do I write a reducer in SpacetimeDB C#?

Write a reducer as a public static method marked with [SpacetimeDB.Reducer] inside a static partial class. The first parameter must be ReducerContext, which provides the sender identity, timestamp, RNG, and database accessors for inserts, finds, updates, and deletes.

Does SpacetimeDB C# support scheduled reducers and timers?

Yes, scheduled tasks use a table with Scheduled and ScheduledAt options pointing to a reducer and a ScheduleAt column. Insert a row with ScheduleAt.Time for one-shot execution or ScheduleAt.Interval for repeating timers; the row is deleted after the reducer runs.

Can SpacetimeDB C# modules make outbound HTTP requests?

Yes, procedures marked [SpacetimeDB.Procedure] can call ctx.Http.Get or send an HttpRequest with custom methods, headers, and bodies. Database access inside procedures requires wrapping work in ctx.WithTx, and network I/O should happen before opening the transaction.

Why must SpacetimeDB C# module methods be public static?

Methods exported through SpacetimeDB attributes, including reducers, procedures, views, and HTTP handlers, must be public static because the generated bindings invoke them from a separate class. Non-static or non-public methods will not be discovered by the code generator.