MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / Table

Interface Table

sdks/rust/src/table.rs:15–51  ·  view source on GitHub ↗

The [`Table`] and [`TableWithPrimaryKey`] traits, which allow certain simple queries of the client cache, and expose row callbacks which run when subscribed rows are inserted, deleted or updated. These traits are implemented by "table handles," types generated by the SpacetimeDB CLI's module-specific codegen which mediate access to tables in the client cache. Obtain a table handle by calling a me

Source from the content-addressed store, hash-verified

13///
14/// For persistent (non-event) tables only. See [`EventTable`] for transient event tables.
15pub trait Table {
16 /// The type of rows stored in this table.
17 type Row: 'static;
18
19 /// The `EventContext` type generated for the module which defines this table.
20 type EventContext;
21
22 /// The number of subscribed rows in the client cache.
23 fn count(&self) -> u64;
24
25 /// An iterator over all the subscribed rows in the client cache.
26 fn iter(&self) -> impl Iterator<Item = Self::Row> + '_;
27
28 type InsertCallbackId;
29 /// Register a callback to run whenever a subscribed row is inserted into the client cache.
30 ///
31 /// The returned [`Self::InsertCallbackId`] can be passed to [`Self::remove_on_insert`]
32 /// to cancel the callback.
33 fn on_insert(
34 &self,
35 callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
36 ) -> Self::InsertCallbackId;
37 /// Cancel a callback previously registered by [`Self::on_insert`], causing it not to run in the future.
38 fn remove_on_insert(&self, callback: Self::InsertCallbackId);
39
40 type DeleteCallbackId;
41 /// Register a callback to run whenever a subscribed row is deleted from the client cache.
42 ///
43 /// The returned [`Self::DeleteCallbackId`] can be passed to [`Self::remove_on_delete`]
44 /// to cancel the callback.
45 fn on_delete(
46 &self,
47 callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
48 ) -> Self::DeleteCallbackId;
49 /// Cancel a callback previously registered by [`Self::on_delete`], causing it not to run in the future.
50 fn remove_on_delete(&self, callback: Self::DeleteCallbackId);
51}
52
53/// Subtrait of [`Table`] implemented only by tables with a column designated as a primary key,
54/// which allows the SDK to identify updates.

Callers

nothing calls this directly

Implementers 15

scheduled_proc_table_table.rsmodules/sdk-test-procedure-cpp/client/
my_table_table.rsmodules/sdk-test-procedure-cpp/client/
pk_uuid_table.rsmodules/sdk-test-procedure-cpp/client/
proc_inserts_into_table.rsmodules/sdk-test-procedure-cpp/client/
message_table.rstemplates/chat-console-rs/src/module_b
user_table.rstemplates/chat-console-rs/src/module_b
person_table.rstemplates/basic-rs/src/module_bindings
person_table.rstemplates/basic-cpp/src/module_binding
sender_right_view_table.rssdks/rust/tests/procedural-view-pk-cli
sender_left_view_table.rssdks/rust/tests/procedural-view-pk-cli
left_source_table.rssdks/rust/tests/procedural-view-pk-cli
right_source_table.rssdks/rust/tests/procedural-view-pk-cli

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…