### Server Setup and Start (Local) Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-oneshot/apps/chat-app/typescript/opus-4-5/postgres/chat-app-20260104-180000/README.md Instructions for setting up and running the chat application's server locally. This involves navigating to the server directory, installing dependencies, pushing database migrations, and starting the development server. ```bash cd server npm install npm run db:push npm run dev ``` -------------------------------- ### Prerequisites for Benchmarking Source: https://github.com/clockworklabs/spacetimedb/blob/master/templates/keynote-2/scripts/README.md One-time setup commands for essential services. Starts PostgreSQL as a system service, starts the Supabase Docker stack, and creates a database for benchmarking. ```bash sudo systemctl start postgresql # Postgres as system service ``` ```bash supabase start # Supabase Docker stack ``` ```bash sudo -u postgres psql -c "CREATE DATABASE bun_bench;" ``` -------------------------------- ### Install and Run Locally Source: https://github.com/clockworklabs/spacetimedb/blob/master/demo/Blackholio/client-ts/README.md Install project dependencies using pnpm and start the development server. Ensure the Rust server is running separately. ```bash pnpm install pnpm dev ``` -------------------------------- ### Configure Node.js Client with Environment Variables Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00300-nodejs.md This example demonstrates how to configure the Node.js client for SpaceTimeDB using environment variables for the host and database name. It also shows how to start the application using npm. ```bash # Configure via environment variables SPACETIMEDB_HOST=ws://localhost:3000 \ SPACETIMEDB_DB_NAME=my-app \ npm run start # Or use a .env file with dotenv ``` -------------------------------- ### Install Client Dependencies and Start Development Server Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-oneshot/apps/chat-app/typescript/opus-4-5/postgres/chat-app-20260104-160000/README.md Installs Node.js dependencies for the React frontend and starts the development server. This requires Node.js 20+. ```bash cd client npm install npm run dev # Start client on port 5174 ``` -------------------------------- ### Complete SpaceTimeDB Server Setup in TypeScript Source: https://github.com/clockworklabs/spacetimedb/blob/master/skills/typescript-server/SKILL.md This example demonstrates a full server setup including table definitions for 'entity' and 'record', schema initialization, and handlers for client connections, disconnections, and reducers for creating entities and adding records. ```typescript import { schema, table, t } from 'spacetimedb/server'; const entity = table( { name: 'entity', public: true }, { identity: t.identity().primaryKey(), name: t.string(), active: t.bool(), } ); const record = table( { name: 'record', public: true, indexes: [{ accessor: 'by_owner', algorithm: 'btree', columns: ['owner'] }], }, { id: t.u64().primaryKey().autoInc(), owner: t.identity(), value: t.u32(), } ); const spacetimedb = schema({ entity, record }); export default spacetimedb; export const onConnect = spacetimedb.clientConnected((ctx) => { const existing = ctx.db.entity.identity.find(ctx.sender); if (existing) ctx.db.entity.identity.update({ ...existing, active: true }); }); export const onDisconnect = spacetimedb.clientDisconnected((ctx) => { const existing = ctx.db.entity.identity.find(ctx.sender); if (existing) ctx.db.entity.identity.update({ ...existing, active: false }); }); export const createEntity = spacetimedb.reducer( { name: t.string() }, (ctx, { name }) => { if (ctx.db.entity.identity.find(ctx.sender)) throw new Error('already exists'); ctx.db.entity.insert({ identity: ctx.sender, name, active: true }); } ); export const addRecord = spacetimedb.reducer( { value: t.u32() }, (ctx, { value }) => { if (!ctx.db.entity.identity.find(ctx.sender)) throw new Error('not found'); ctx.db.record.insert({ id: 0n, owner: ctx.sender, value }); } ); ``` -------------------------------- ### Initialize TanStack SpacetimeDB Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00170-tanstack.md Creates a new SpacetimeDB project with a SpacetimeDB module and a TanStack Start frontend. This command also starts the local SpacetimeDB server, publishes the module, generates TypeScript bindings, and launches the development server. ```bash spacetime dev --template tanstack-ts ``` -------------------------------- ### SpacetimeDB CLI Interaction Example Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00275-deno.md Demonstrates interacting with a SpacetimeDB application using the command-line interface. Users can add data, query tables, and call reducers directly. ```bash Connecting to SpacetimeDB... URI: ws://localhost:3000 Module: deno-ts Connected to SpacetimeDB! Identity: abc123def456... Current people (0): (none yet) Commands: - Add a person with that name list - Show all people hello - Greet everyone (check server logs) Ctrl+C - Quit > Alice > [Added] Alice > Bob > [Added] Bob > list > People in database: - Alice - Bob > hello > Called sayHello reducer (check server logs) ``` -------------------------------- ### Create SpacetimeDB C++ Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00700-cpp.md Initializes a new SpacetimeDB C++ project using the `spacetime dev` command with a basic template. This command automates the setup, including CMake and Emscripten integration, and starts a local development server. ```bash spacetime dev --template basic-cpp ``` -------------------------------- ### Create SpacetimeDB Project with C# Template Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00600-c-sharp.md Creates a new SpacetimeDB project using the 'basic-cs' template. This command initializes the project structure, starts a local SpacetimeDB server, compiles the module, and generates C# client bindings. ```bash spacetime dev --template basic-cs ``` -------------------------------- ### SpacetimeDB Start Output Example Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00300-resources/00200-reference/00100-cli-reference/00200-standalone-config.md This output shows the version of the standalone SpacetimeDB and the path to its data directory, which is essential for locating the configuration file. ```bash spacetimedb-standalone version: 1.0.0 spacetimedb-standalone path: /home/user/.local/share/spacetime/bin/1.0.0/spacetimedb-standalone database running in data directory /home/user/.local/share/spacetime/data ``` -------------------------------- ### Create SpacetimeDB Node.js Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00300-nodejs.md Initializes a new SpacetimeDB project with a Node.js TypeScript client. This command starts the local SpacetimeDB server, publishes the module, generates TypeScript bindings, and runs the Node.js client. ```bash spacetime dev --template nodejs-ts ``` -------------------------------- ### SpacetimeDB C# Module Structure and Example Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00600-c-sharp.md Illustrates the typical project structure for a SpacetimeDB C# application, highlighting the server-side module and auto-generated client bindings. It includes an example of defining a 'Person' table and 'Add' and 'SayHello' reducers. ```csharp using SpacetimeDB; public static partial class Module { [SpacetimeDB.Table(Accessor = "Person", Public = true)] public partial struct Person { public string Name; } [SpacetimeDB.Reducer] public static void Add(ReducerContext ctx, string name) { ctx.Db.Person.Insert(new Person { Name = name }); } [SpacetimeDB.Reducer] public static void SayHello(ReducerContext ctx) { foreach (var person in ctx.Db.Person.Iter()) { Log.Info($"Hello, {person.Name}!"); } Log.Info("Hello, World!"); } } ``` -------------------------------- ### Start Application with Docker Compose Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-oneshot/apps/chat-app/typescript/opus-4-5/postgres/chat-app-20260104-120000/README.md This command builds and starts the entire application, including the backend, frontend, and database, using Docker Compose. It simplifies the local development environment setup. ```bash docker-compose up --build -d ``` -------------------------------- ### Create SpacetimeDB Project with Bun Template Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00250-bun.md Initializes a new SpacetimeDB project with a SpacetimeDB module and a Bun client. This command also starts the local SpacetimeDB server, publishes the module, and generates TypeScript bindings. ```bash spacetime dev --template bun-ts ``` -------------------------------- ### Deno Client Connection and CLI Setup (TypeScript) Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00275-deno.md Establishes a connection to SpacetimeDB using `DbConnection.builder()`, subscribes to table changes, and sets up an interactive CLI. It demonstrates loading and saving authentication tokens using Deno's file system APIs. ```typescript import { DbConnection } from './module_bindings/index.ts'; // Build and establish connection DbConnection.builder() .withUri(HOST) .withDatabaseName(DB_NAME) .withToken(await loadToken()) // Load saved token from file .onConnect((conn, identity, token) => { console.log('Connected! Identity:', identity.toHexString()); saveToken(token); // Save token for future connections // Subscribe to all tables conn.subscriptionBuilder() .onApplied((ctx) => { // Show current data, start CLI setupCLI(conn); }) .subscribeToAllTables(); // Listen for table changes conn.db.person.onInsert((ctx, person) => { console.log(`[Added] ${person.name}`); }); }) .build(); ``` -------------------------------- ### Create SpacetimeDB Deno Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00275-deno.md Initializes a new SpacetimeDB project with a Deno TypeScript template. This command starts the local SpacetimeDB server, publishes the module, and generates TypeScript bindings for the Deno client. ```bash spacetime dev --template deno-ts ``` -------------------------------- ### Create Nuxt SpacetimeDB Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00155-nuxt.md Initializes a new Nuxt.js project with SpacetimeDB integration. This command starts the local SpacetimeDB server, publishes the module, generates TypeScript bindings, and launches the Nuxt development server. ```bash spacetime dev --template nuxt-ts ``` -------------------------------- ### Create SpacetimeDB Svelte Project with CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00160-svelte.md Initializes a new SpacetimeDB project with a Svelte TypeScript client. This command starts the local SpacetimeDB server, publishes the module, generates TypeScript bindings, and launches the Svelte development server. ```bash spacetime dev --template svelte-ts ``` -------------------------------- ### Create SpacetimeDB Project with Browser Template Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00180-browser.md Initiates a new SpacetimeDB project configured for browser use with a TypeScript module. This command starts the local SpacetimeDB server, publishes the module, and generates TypeScript client bindings. ```bash spacetime dev --template browser-ts ``` -------------------------------- ### SpacetimeDB Rust Module Example Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00500-rust.md Demonstrates a basic SpacetimeDB Rust module with a `Person` table and two reducers: `add` to insert data and `say_hello` to log messages. It utilizes the `spacetimedb` crate for table and reducer definitions. ```rust use spacetimedb::{ReducerContext, Table}; #[spacetimedb::table(accessor = person, public)] pub struct Person { name: String, } #[spacetimedb::reducer] pub fn add(ctx: &ReducerContext, name: String) { ctx.db.person().insert(Person { name }); } #[spacetimedb::reducer] pub fn say_hello(ctx: &ReducerContext) { for person in ctx.db.person().iter() { log::info!("Hello, {}!", person.name); } log::info!("Hello, World!"); } ``` -------------------------------- ### Create SpacetimeDB Project with TypeScript Template Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00400-typescript.md Initializes a new SpacetimeDB project using the basic TypeScript template. This command sets up the project structure, starts a local SpacetimeDB server, publishes the module, and generates TypeScript client bindings. ```bash spacetime dev --template basic-ts ``` -------------------------------- ### Create SpacetimeDB React Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00100-react.md Initializes a new SpacetimeDB project with a React client using the 'react-ts' template. This command starts the local SpacetimeDB server, publishes the module, generates TypeScript bindings, and launches the React development server. ```bash spacetime dev --template react-ts ``` -------------------------------- ### Create SpacetimeDB Remix Project with CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00175-remix.md Initiates a new SpacetimeDB project with a Remix client and TypeScript bindings. This command starts the local SpacetimeDB server, publishes the module, generates necessary types, and launches the Remix development server. ```bash spacetime dev --template remix-ts ``` -------------------------------- ### Start SpacetimeDB Development Server Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00200-core-concepts/00100-databases/00200-spacetime-dev.md Initiates the interactive development process for a SpacetimeDB module. If a project exists, it enters development mode directly; otherwise, it guides through setup. ```bash spacetime dev ``` -------------------------------- ### Integrate SpacetimeDB Client in HTML Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00180-browser.md Demonstrates how to load the bundled SpacetimeDB client bindings and establish a real-time connection to the SpacetimeDB server within an HTML file. It shows how to subscribe to data changes and interact with the database. ```html ``` -------------------------------- ### Frontend Setup and Development Commands (Bash) Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-oneshot/apps/chat-app/typescript/grok-code/postgres/chat-app-20260128-112222/README.md Commands to set up and run the frontend React application. This involves installing dependencies and starting the development server. ```bash cd client npm install npm run dev # Start development server ``` -------------------------------- ### Backend Setup and Development Commands (Bash) Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-oneshot/apps/chat-app/typescript/grok-code/postgres/chat-app-20260128-112222/README.md Commands to set up and run the backend Node.js server. This includes installing dependencies, generating and migrating the database schema, and starting the development server. ```bash cd server npm install npm run db:generate # Generate database schema npm run db:migrate # Run migrations npm run dev # Start development server ``` -------------------------------- ### Quickstart Guide Smoke Test Source: https://github.com/clockworklabs/spacetimedb/blob/master/TESTING.md Rust code for a smoketest that replays the quickstart guide for both Rust and C# to ensure documentation and basic functionality are working correctly. ```rust crates/smoketests/tests/smoketests/quickstart.rs ``` -------------------------------- ### Project Setup with .NET CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00200-core-concepts/00600-clients/00600-csharp-reference.md Instructions on how to add the SpacetimeDB SDK to a .NET console application using the `dotnet CLI`. ```APIDOC ## Project Setup ### Using the `dotnet` CLI tool If you would like to create a console application using .NET, you can create a new project using `dotnet new console` and add the SpacetimeDB SDK to your dependencies: ```bash dotnet add package SpacetimeDB.ClientSDK ``` (See also the [CSharp Quickstart](../../00100-intro/00200-quickstarts/00600-c-sharp.md) for an in-depth example of such a console application.) ``` -------------------------------- ### Project Setup Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00200-core-concepts/00600-clients/00500-rust-reference.md Instructions for setting up a new Rust project and adding the SpacetimeDB SDK as a dependency. ```APIDOC ## Project setup First, create a new project using `cargo new` and add the SpacetimeDB SDK to your dependencies: ```bash car go add spacetimedb_sdk ``` ``` -------------------------------- ### Install SpacetimeDB CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00100-getting-started/00500-faq.md Installs the SpacetimeDB command-line interface. This is the first step to start developing with SpacetimeDB. ```bash curl -sSf https://install.spacetimedb.com | sh ``` -------------------------------- ### Call SetupArena on Subscription Applied Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00300-tutorials/00300-unity-tutorial/00400-part-3.md Integrate arena setup into the client's subscription handling logic. This ensures the arena is created after the initial data synchronization from the server. ```csharp private void HandleSubscriptionApplied(SubscriptionEventContext ctx) { Debug.Log("Subscription applied!"); OnSubscriptionApplied?.Invoke(); // Once we have the initial subscription sync'd to the client cache // Get the world size from the config table and set up the arena var worldSize = Conn.Db.Config.Id.Find(0).WorldSize; SetupArena(worldSize); } ``` -------------------------------- ### Initialize SpacetimeDB Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/templates/basic-cs/README.md Creates a new project using the basic C# template, which sets up the server, client, and bindings. ```bash spacetime dev --template basic-cs ``` -------------------------------- ### Project Structure Overview Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00170-tanstack.md Illustrates the typical directory structure of a SpacetimeDB project created with the TanStack Start template. It highlights the separation between server-side SpacetimeDB module code and the client-side TanStack Start frontend. ```treeview my-spacetime-app/ ├── spacetimedb/ # Your SpacetimeDB module │ └── src/ │ └── index.ts # Server-side logic ├── src/ # TanStack Start frontend │ ├── router.tsx # QueryClient + SpacetimeDB setup │ ├── routes/ │ │ ├── __root.tsx # Root layout │ │ └── index.tsx # Main app component │ └── module_bindings/ # Auto-generated types └── package.json ``` -------------------------------- ### Example Publish Command Source: https://github.com/clockworklabs/spacetimedb/blob/master/crates/bindings/README.md An example of publishing a SpacetimeDB module to a database named `silly_demo_app`. ```bash spacetime publish silly_demo_app ``` -------------------------------- ### Install Client Dependencies and Run React App Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-oneshot/apps/chat-app/typescript/opus-4-5/spacetime/chat-app-20260105-180000/README.md Commands to navigate to the client directory, install npm dependencies, and start the development server for the React frontend. ```bash cd client npm install npm run dev ``` -------------------------------- ### TanStack Start Frontend Data Integration Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00170-tanstack.md Shows how to use SpacetimeDB hooks within a TanStack Start application to fetch and display data. `useSpacetimeDBQuery` subscribes to table changes, and `useReducer` provides a function to call server-side reducers. ```typescript import { useSpacetimeDBQuery, useReducer } from 'spacetimedb/tanstack'; import { tables, reducers } from '../module_bindings'; function App() { const [people, loading] = useSpacetimeDBQuery(tables.person); const addPerson = useReducer(reducers.add); if (loading) return

Loading...

; return ( ); } ``` -------------------------------- ### Interact with SpacetimeDB CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00250-bun.md Demonstrates how to use the SpacetimeDB CLI to interact with the application. This includes calling reducers like 'add' to insert data and querying the database. Changes made via the CLI are reflected in the Bun client in real-time. ```bash # Call the add reducer to insert a person spacetime call add Charlie ``` -------------------------------- ### Install .NET WASI Workload Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00600-c-sharp.md Installs the experimental WASI workload for .NET, which is required for compiling SpacetimeDB C# modules to WebAssembly. This is a prerequisite for building SpacetimeDB applications in C#. ```bash dotnet workload install wasi-experimental ``` -------------------------------- ### Calling SetupArena in HandleSubscriptionApplied Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00300-tutorials/00500-godot-tutorial/00400-part-3.md This C# method is called after the initial server synchronization. It retrieves the world size from the config table and then calls SetupArena to initialize the game environment. ```csharp private void HandleSubscriptionApplied(SubscriptionEventContext ctx) { GD.Print("Subscription applied!"); OnSubscriptionApplied?.Invoke(); // Once we have the initial subscription sync'd to the client cache // Get the world size from the config table and set up the arena var worldSize = Conn.Db.Config.Id.Find(0).WorldSize; SetupArena(worldSize); } ``` -------------------------------- ### Install Emscripten SDK Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00700-cpp.md Installs and activates the Emscripten SDK, ensuring that `emcc` and the CMake toolchain file are available on the system's PATH. This is a prerequisite for building C++ projects for WebAssembly. ```bash # From your emsdk directory (after downloading/cloning) # Windows PowerShell ./emsdk install 4.0.21 ./emsdk activate 4.0.21 ./emsdk_env.ps1 # macOS/Linux ./emsdk install 4.0.21 ./emsdk activate 4.0.21 source ./emsdk_env.sh ``` -------------------------------- ### Install Dependencies Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-sequential-upgrade/perf-benchmark/README.md Installs the necessary Node.js packages for the benchmark harness. Run this command in the project directory. ```bash npm install ``` -------------------------------- ### C# ArrayList Example with Output Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/STYLE.md Provides a practical example of using the ArrayList class in C#, including adding elements and displaying its properties. The expected console output is included as a comment. ```csharp using System; using System.Collections; public class SamplesArrayList { public static void Main() { // Creates and initializes a new ArrayList. ArrayList myAL = new ArrayList(); myAL.Add("Hello"); myAL.Add("World"); myAL.Add("!"); // Displays the properties and values of the ArrayList. Console.WriteLine( "myAL" ); Console.WriteLine( " Count: {0}", myAL.Count ); Console.WriteLine( " Capacity: {0}", myAL.Capacity ); Console.Write( " Values:" ); PrintValues( myAL ); } public static void PrintValues( IEnumerable myList ) { foreach ( Object obj in myList ) Console.Write( " {0}", obj ); Console.WriteLine(); } } /* This code produces output similar to the following: myAL Count: 3 Capacity: 4 Values: Hello World ! */ ``` -------------------------------- ### Install Server Dependencies and Setup Database Source: https://github.com/clockworklabs/spacetimedb/blob/master/tools/llm-oneshot/apps/chat-app/typescript/opus-4-5/postgres/chat-app-20260104-160000/README.md Installs Node.js dependencies for the server and pushes database schema changes to PostgreSQL. Ensure Node.js 20+ and a local PostgreSQL instance are available. ```bash cd server npm install # Set DATABASE_URL if not using default npm run db:push # Create tables npm run dev # Start server on port 3001 ``` -------------------------------- ### Configure and run application with Bun Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00250-bun.md This demonstrates how to configure and run a SpaceAndTimeDB application using Bun. It shows setting environment variables directly in the command or via a .env file, leveraging Bun's native features like WebSocket support and built-in TypeScript. ```bash # Configure via environment variables SPACETIMEDB_HOST=ws://localhost:3000 \ SPACETIMEDB_DB_NAME=my-app \ bun run start # Or create a .env file (Bun loads it automatically) echo "SPACETIMEDB_HOST=ws://localhost:3000" > .env echo "SPACETIMEDB_DB_NAME=my-app" >> .env bun run start ``` -------------------------------- ### Test SpacetimeDB C++ App with CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00700-cpp.md Demonstrates how to interact with a SpacetimeDB C++ application using the SpacetimeDB CLI. This includes calling reducers (`add`, `say_hello`), querying data with SQL, and viewing module logs. ```bash cd my-spacetime-app # Insert a person spacetime call add Alice # Query the person table spacetime sql "SELECT * FROM person" # Call say_hello to greet everyone spacetime call say_hello # View the module logs spacetime logs ``` -------------------------------- ### Accessing a Table Handle via Db Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00200-core-concepts/00600-clients/00600-csharp-reference.md Example of how to get a handle to a specific table (e.g., User) from the remote database context. ```csharp var conn = ConnectToDB(); // Get a handle to the User table var tableHandle = conn.Db.User; ``` -------------------------------- ### Initialize Database and Spawn Food in C++ Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00300-tutorials/00500-godot-tutorial/00400-part-3.md This C++ code demonstrates initializing the database with a world size configuration and then spawning food entities. It uses the SPACETIMEDB_INIT macro for initial setup and a separate reducer for spawning. ```cpp // Note the SPACETIMEDB_INIT macro. // This indicates to SpacetimeDB that it should be called // once upon database creation. SPACETIMEDB_INIT(init, ReducerContext ctx) { LOG_INFO("Initializing..."); ctx.db[config].insert(Config{0, 1000}); return Ok(); } ``` ```cpp const int32_t FOOD_MASS_MIN = 2; const int32_t FOOD_MASS_MAX = 4; const size_t TARGET_FOOD_COUNT = 600; float mass_to_radius(int32_t mass) { return std::sqrt(static_cast(mass)); } SPACETIMEDB_REDUCER(spawn_food, ReducerContext ctx) { // Check if there are any players logged in bool has_players = false; for (const auto& _ : ctx.db[player]) { has_players = true; break; } if (!has_players) { // Are there no logged in players? Skip food spawn. return Ok(); } auto config_opt = ctx.db[config_id].find(0); if (!config_opt.has_value()) { return Err("Config not found"); } int64_t world_size = config_opt.value().world_size; auto& rng = ctx.rng(); // Count current food uint64_t food_count = 0; for (const auto& _ : ctx.db[food]) { food_count++; } while (food_count < TARGET_FOOD_COUNT) { int32_t food_mass = rng.gen_range(FOOD_MASS_MIN, FOOD_MASS_MAX); float food_radius = mass_to_radius(food_mass); float x = rng.gen_range(food_radius, static_cast(world_size) - food_radius); float y = rng.gen_range(food_radius, static_cast(world_size) - food_radius); auto inserted_entity = ctx.db[entity].insert(Entity{0, {x, y}, food_mass}); ctx.db[food].insert(Food{inserted_entity.entity_id}); food_count += 1; LOG_INFO("Spawned food! " + std::to_string(inserted_entity.entity_id)); } return Ok(); } ``` -------------------------------- ### Get UDbConnection Builder Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00200-core-concepts/00600-clients/00800-unreal-reference.md Obtain a builder instance to configure and create a UDbConnection. This is the starting point for establishing a connection to a SpacetimeDB instance. ```cpp class UDbConnection { UFUNCTION(BlueprintCallable, Category = "SpacetimeDB") static UDbConnectionBuilder* Builder(); }; ``` -------------------------------- ### Interact with SpacetimeDB using CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00100-react.md Demonstrates how to interact with a SpacetimeDB project using the SpacetimeDB CLI. This includes calling reducers to modify data, executing SQL queries to retrieve data, and viewing module logs. ```bash cd my-spacetime-app # Call the add reducer to insert a person spacetime call add Alice # Query the person table spacetime sql "SELECT * FROM person" name --------- "Alice" # Call sayHello to greet everyone spacetime call say_hello # View the module logs spacetime logs 2025-01-13T12:00:00.000000Z INFO: Hello, Alice! 2025-01-13T12:00:00.000000Z INFO: Hello, World! ``` -------------------------------- ### Rust Example: Finding Rows in a Table Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/STYLE.md Demonstrates how to find rows in a SpacetimeDB table based on a unique or primary key column. This example uses Rust and assumes context `ctx` and a table with a unique column. ```rust ctx.db.{table}().{column}().find({value}) ``` ```rust ctx.db.people().name().find("Billy") ``` -------------------------------- ### SpacetimeDB CLI for Reducer Calls and Queries (Bash) Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00300-nodejs.md Demonstrates how to interact with a SpacetimeDB application using the command-line interface. This includes calling reducers like 'add' and 'say_hello' to modify data and execute server-side logic, as well as querying the database using SQL. ```bash # Add a person spacetime call add Alice spacetime call add Bob # Greet everyone (check server logs) spacetime call say_hello # Query the database spacetime sql "SELECT * FROM person" ``` -------------------------------- ### Run Deno Client for SpacetimeDB Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00275-deno.md Commands to run the Deno client application. `pnpm run dev` or `npm run dev` will run the client with auto-reloading during development. `pnpm run start` or `npm run start` will run the client once. ```bash # Run with auto-reload during development pnpm run dev # or: npm run dev # Or run once pnpm run start # or: npm run start ``` -------------------------------- ### Test SpacetimeDB Rust App with CLI Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00500-rust.md Shows how to interact with a SpacetimeDB Rust application using the SpacetimeDB CLI. Includes commands to call reducers (`add`, `say_hello`), query data using SQL, and view module logs. ```bash cd my-spacetime-app # Call the add reducer to insert a person spacetime call add Alice # Query the person table spacetime sql "SELECT * FROM person" name --------- "Alice" # Call say_hello to greet everyone spacetime call say_hello # View the module logs spacetime logs 2025-01-13T12:00:00.000000Z INFO: Hello, Alice! 2025-01-13T12:00:00.000000Z INFO: Hello, World! ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/clockworklabs/spacetimedb/blob/master/crates/bindings-cpp/CMakeLists.txt Sets the minimum CMake version and defines the project name, version, and languages. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.15) project(SpacetimeDBCppModuleLibrary VERSION 2.6.0 LANGUAGES CXX) ``` -------------------------------- ### Deno package.json for SpacetimeDB Project Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00100-intro/00200-quickstarts/00275-deno.md This JSON object defines scripts and dependencies for a Deno project using SpacetimeDB. It includes scripts for development ('dev') and starting the application ('start'), as well as a command to generate module bindings. The 'spacetimedb' dependency is declared, allowing Deno to resolve it. ```json { "scripts": { "dev": "deno run --watch --allow-net --allow-read --allow-write --allow-env --unstable-sloppy-imports src/main.ts", "start": "deno run --allow-net --allow-read --allow-write --allow-env --unstable-sloppy-imports src/main.ts", "spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --module-path spacetimedb" }, "dependencies": { "spacetimedb": "workspace:*" } } ``` -------------------------------- ### Initialize and Publish Project (C#) Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00200-core-concepts/00100-databases/00500-cheat-sheet.md Use this command to initialize a new SpacetimeDB project with C# and publish it to a database. ```bash spacetime init --lang csharp --project-path my-project my-project cd my-project spacetime login spacetime publish ``` -------------------------------- ### Disable Client Development Server Source: https://github.com/clockworklabs/spacetimedb/blob/master/docs/docs/00200-core-concepts/00100-databases/00200-spacetime-dev.md Starts the SpacetimeDB development server without running the client development server. This is useful for server-only module development. ```bash spacetime dev --server-only ```