Skip to content

Docs - insert -> try_insert#4025

Merged
bfops merged 4 commits intomasterfrom
bfops/docs-fix
Jan 14, 2026
Merged

Docs - insert -> try_insert#4025
bfops merged 4 commits intomasterfrom
bfops/docs-fix

Conversation

@bfops
Copy link
Collaborator

@bfops bfops commented Jan 13, 2026

Description of Changes

Fix a small docs thing that a user noticed in #3970.

API and ABI breaking changes

None

Expected complexity level and risk

1

Testing

  • I copy-pasted the new client_connected reducer into a test project and ran spacetime build

@bfops
Copy link
Collaborator Author

bfops commented Jan 13, 2026

/update-llm-benchmarks

@bfops bfops requested a review from jdetter January 13, 2026 18:39
Copy link
Collaborator

@jdetter jdetter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! Tested with this example:

use spacetimedb::{table, reducer, Table, ReducerContext, Identity, Timestamp, ConnectionId};

#[table(name = sessions)]
pub struct Session {
    #[unique]
    pub connection_id: ConnectionId,
    pub identity: Identity,
    pub connected_at: Timestamp,
}

#[reducer(client_connected)]
pub fn on_connect(ctx: &ReducerContext) -> Result<(), String> {
    log::info!("Client connected: {}", ctx.sender);

    // ctx.connection_id is guaranteed to be Some(...)
    let conn_id = ctx.connection_id.unwrap();

    // Initialize client session
    ctx.db.sessions().try_insert(Session {
        connection_id: conn_id,
        identity: ctx.sender,
        connected_at: ctx.timestamp,
    })?;

    Ok(())
}


#[reducer(client_disconnected)]
pub fn on_disconnect(ctx: &ReducerContext) -> Result<(), String> {
    log::info!("Client disconnected: {}", ctx.sender);

    // ctx.connection_id is guaranteed to be Some(...)
    let conn_id = ctx.connection_id.unwrap();

    // Clean up client session
    ctx.db.sessions().connection_id().delete(&conn_id);

    Ok(())
}

@clockwork-labs-bot
Copy link
Collaborator

clockwork-labs-bot commented Jan 13, 2026

LLM Benchmark Results (ci-quickfix)

Language Mode Category Tests Passed Pass % Task Pass %
Rust rustdoc_json basics 20/27 74.1% 75.0%
Rust rustdoc_json schema 18/30 60.0% 50.0%
Rust rustdoc_json total 38/57 66.7% 63.6%
C# docs basics 27/27 100.0% 100.0%
C# docs schema 28/34 82.4% 80.0%
C# docs total 55/61 90.2% 90.9%

Generated at: 2026-01-13T21:47:49.643Z

@bfops bfops enabled auto-merge January 13, 2026 21:04
@bfops bfops disabled auto-merge January 13, 2026 21:16
@bfops
Copy link
Collaborator Author

bfops commented Jan 13, 2026

/update-llm-benchmark

@bfops bfops added this pull request to the merge queue Jan 13, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 14, 2026
@bfops bfops added this pull request to the merge queue Jan 14, 2026
Merged via the queue into master with commit c27db13 Jan 14, 2026
59 of 62 checks passed
@bfops bfops deleted the bfops/docs-fix branch January 15, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants