cpp-server

Provides reference patterns for writing SpacetimeDB server modules in C++.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing SpacetimeDB server modules in C++ requires knowing the exact macro-based API for tables, reducers, indexes, and lifecycle hooks, which is easy to get wrong without a canonical reference.

Core Features & Use Cases

  • Table and Schema Definition: Register structs with SPACETIMEDB_STRUCT and SPACETIMEDB_TABLE macros, including primary keys, auto-increment, unique constraints, and btree indexes.
  • Reducer and Lifecycle Patterns: Implement reducers returning ReducerResult, plus init, client-connected, and client-disconnected hooks with authentication via ctx.sender().
  • Use Case: A developer building a multiplayer game backend in C++ uses this reference to define entity tables, write reducers for player actions, and schedule repeating reminders with ScheduleAt.

Quick Start

Ask the AI to write a SpacetimeDB C++ module with a table and a reducer using the cpp-server reference.

Frequently Asked Questions about cpp-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 plain struct, register it with SPACETIMEDB_STRUCT listing its fields, then declare it with SPACETIMEDB_TABLE specifying an accessor name and Public or Private visibility. Add constraints with FIELD_PrimaryKey, FIELD_PrimaryKeyAutoInc, FIELD_Unique, or FIELD_Index macros.

How do I write a reducer in SpacetimeDB C++?

Use the SPACETIMEDB_REDUCER macro with a ReducerContext parameter and your arguments, returning ReducerResult via Ok() or Err(message). Access tables through ctx.db[accessor] to insert, find, filter, update, or delete rows.

Does the SpacetimeDB C++ SDK support scheduled reducers?

Yes, create a table with a ScheduleAt column and register it with SPACETIMEDB_SCHEDULE pointing to the target reducer. Insert rows with ScheduleAt::time for one-time execution or ScheduleAt::interval for repeating tasks.

How do I check caller identity in a SpacetimeDB C++ reducer?

Call ctx.sender() inside the reducer to get the caller's Identity and compare it against an owner column for authorization. The ReducerContext also provides ctx.timestamp, ctx.rng(), and ctx.sender_auth() for JWT claims.

What C++ types map to SpacetimeDB table columns?

Supported types include standard integers, u128/u256 and i128/i256, float, double, bool, std::string, std::vector<T>, std::optional<T>, Identity, ConnectionId, Timestamp, TimeDuration, and ScheduleAt. Custom structs and enums are registered with SPACETIMEDB_STRUCT and SPACETIMEDB_ENUM.