Skip to content

Commit

Permalink
Edits
Browse files Browse the repository at this point in the history
  • Loading branch information
kazimuth committed Jan 10, 2025
1 parent f239fcc commit 09b3a03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion crates/bindings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ fn do_something(ctx: &ReducerContext) {
See [reducers](#reducers) for more information on declaring reducers.
See the [`#[table]` macro](macro@crate::table) for more information on declaring and using tables.

<!-- TODO: outline generated methods here, split up by annotations required. -->

#### Public and Private tables

By default, tables are considered **private**. This means that they are only readable by the table owner and by reducers. Reducers run inside the database, so clients cannot see private tables at all.
Expand Down Expand Up @@ -313,7 +315,7 @@ enum GiveItemError {
}

#[reducer]
fn give_player_item(ctx: &ReducerContext, player_id: u64, item_id: u64) {
fn give_player_item(ctx: &ReducerContext, player_id: u64, item_id: u64) -> Result<(), GiveItemError> {
/* ... */
}
```
Expand Down
8 changes: 5 additions & 3 deletions crates/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ fn delete_id(ctx: &ReducerContext, id: u64) {
/// They are regular structs, with no special behavior.
/// In particular, modifying them does not automatically modify the database!
///
/// Instead, a struct implementing [`Table<Row = Self>`] is generated. This can be looked up in a [`ReducerContext`]
/// using `ctx.db.{table_name}()`. This method represents a handle to a database table, and can be used to
/// Instead, a type implementing [`Table<Row = Self>`] is generated. This can be looked up in a [`ReducerContext`]
/// using `ctx.db.{table_name}()`. This type represents a handle to a database table, and can be used to
/// iterate and modify the table's elements. It is a view of the entire table -- the entire set of rows at the time of the reducer call.
///
/// # Example
Expand All @@ -288,7 +288,6 @@ fn delete_id(ctx: &ReducerContext, id: u64) {
/// use spacetimedb::{table, ReducerContext};
///
/// #[table(name = users, public,
/// index(name = id_and_username, btree(columns = [id, username])),
/// index(name = popularity_and_username, btree(columns = [popularity, username])),
/// )]
/// pub struct User {
Expand All @@ -313,13 +312,16 @@ fn delete_id(ctx: &ReducerContext, id: u64) {
/// log::debug!("{:?}", user);
/// }
///
/// /*
/// TODO: whoops, use filter, and popularity_and_username.
/// // For every named `index`, the table has an extra method
/// // for getting a corresponding `spacetimedb::BTreeIndex`.
/// let by_id_and_username: spacetimedb::BTreeIndex<_, (u32, String), _> =
/// users.id_and_username();
/// let mut billy: User = by_id_and_username.find((&57, &"Billy".to_string()));
/// billy.popularity += 5;
/// by_id_and_username.update(billy);
/// */
///
/// // For every `#[unique]` or `#[primary_key]` field,
/// // the table has an extra method that allows getting a
Expand Down

0 comments on commit 09b3a03

Please sign in to comment.