Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ If this publish is a major upgrade from 1.x to 2.0, read [1.x to 2.0 Upgrade Not

To completely reset your database and delete all data:

<!-- Docs maintenance: keep the simple reset example as bare `--delete-data`.
The CLI default mode is `always`; spell out `--delete-data=<mode>` only when
documenting the available modes or showing non-interactive/scripted usage. -->

```bash
spacetime publish <DATABASE_NAME> --delete-data
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ interface IRemoteDbContext
```

`Reducers` will have methods to invoke each reducer defined by the module,
plus methods for adding and removing callbacks on each of those reducers.
plus events for observing the result of reducer calls made by this connection.

##### Example

```csharp
var conn = ConnectToDB();

// Register a callback to be run every time the SendMessage reducer is invoked
// Register a callback to observe the result of SendMessage calls made by this connection.
conn.Reducers.OnSendMessage += Reducer_OnSendMessageEvent;
```

Expand Down Expand Up @@ -711,9 +711,9 @@ record Event<R>
}
```

Event when we are notified that a reducer ran in the remote database. The [`ReducerEvent`](#record-reducerevent) contains metadata about the reducer run, including its arguments and termination [`Status`](#record-status).
Event when we are notified of the result of a reducer call made by this connection. The [`ReducerEvent`](#record-reducerevent) contains metadata about the reducer run, including its arguments and termination [`Status`](#record-status).

This event is passed to row callbacks resulting from modifications by the reducer.
For changes caused by other clients' reducer calls, use table row callbacks or event tables rather than reducer callbacks. The server does not broadcast reducer arguments globally.

#### Variant `SubscribeApplied`

Expand Down Expand Up @@ -1084,13 +1084,14 @@ int CountPlayersAtLevel(RemoteTables tables, uint level) => tables.Player.Level.

## Observe and invoke reducers

All [`IDbContext`](#interface-idbcontext) implementors, including [`DbConnection`](#type-dbconnection) and [`EventContext`](#type-eventcontext), have a `.Reducers` property, which in turn has methods for invoking reducers defined by the module and registering callbacks on it.
All [`IDbContext`](#interface-idbcontext) implementors, including [`DbConnection`](#type-dbconnection) and [`EventContext`](#type-eventcontext), have a `.Reducers` property. Generated module bindings expose one invoke method and one result event for each reducer.

Each reducer defined by the module has three methods on the `.Reducers`:
For a reducer named `send_message`, generated C# bindings use PascalCase names:

- An invoke method, whose name is the reducer's name converted to snake case, like `set_name`. This requests that the module run the reducer.
- A callback registation method, whose name is prefixed with `on_`, like `on_set_name`. This registers a callback to run whenever we are notified that the reducer ran, including successfully committed runs and runs we requested which failed. This method returns a callback id, which can be passed to the callback remove method.
- A callback remove method, whose name is prefixed with `remove_on_`, like `remove_on_set_name`. This cancels a callback previously registered via the callback registration method.
- An invoke method, like `SendMessage(...)`. This requests that the module run the reducer.
- A result event, like `OnSendMessage`. This event fires on the calling connection when SpacetimeDB reports that reducer call's result, including committed, failed, and out-of-energy statuses.

Reducer result events are not global notifications. They are for reducer calls made by this connection. To notify other clients that something happened, write to a public table or event table and subscribe to it.

## Identify a client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ These apply to all selected databases:

- `--server`: target server
- `--break-clients`: allow breaking changes
- `--delete-data`: clear database data
- `--delete-data=<mode>`: clear database data (`always`, `on-conflict`, or `never`)
- `--yes` / `--force`: skip confirmation prompts

### Per-database overrides
Expand Down
4 changes: 4 additions & 0 deletions skills/cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ spacetime publish my-database --server local --yes
spacetime publish my-database --delete-data=always --yes
```

Bare `--delete-data` defaults to `always`. Keep simple interactive docs examples
bare, and use `--delete-data=always` for scripted/non-interactive examples that
also pass `--yes`.

### Database Interaction

```bash
Expand Down
Loading