Skip to content

Commit

Permalink
Describe how to define multiple tables with the same type
Browse files Browse the repository at this point in the history
Fixes #90.
  • Loading branch information
RReverser committed Nov 26, 2024
1 parent 97be43c commit 81b4fb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/modules/c-sharp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,17 @@ public partial struct Person
}
```

You can create multiple tables backed by items of the same type by applying it with different names. For example, to store active and archived posts separately and with different privacy rules, you can declare two tables like this:

```csharp
[SpacetimeDB.Table(Name = "posts", Public = true)]
[SpacetimeDB.Table(Name = "archived_posts", Public = false)]
public partial struct Post {
public string Title;
public string Body;
}
```

#### Column attributes

Attribute `[SpacetimeDB.Column]` can be used on any field of a `SpacetimeDB.Table`-marked `struct` or `class` to customize column attributes as seen above.
Expand Down
11 changes: 11 additions & 0 deletions docs/modules/rust/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ struct Person {
}
```

You can create multiple tables backed by items of the same type by applying it with different names. For example, to store active and archived posts separately and with different privacy rules, you can declare two tables like this:

```rust
#[table(name = posts, public)]
#[table(name = archived_posts)]
struct Post {
title: String,
body: String,
}
```

### Defining reducers

`#[reducer]` is always applied to top level Rust functions. They can take arguments of types known to SpacetimeDB (just like fields of structs must be known to SpacetimeDB), and either return nothing, or return a `Result<(), E: Debug>`.
Expand Down

0 comments on commit 81b4fb8

Please sign in to comment.