Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe how to define multiple tables with the same type #113

Merged
merged 3 commits into from
Jan 6, 2025
Merged
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
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 = "Post", Public = true)]
[SpacetimeDB.Table(Name = "ArchivedPost", 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 = post, public)]
#[table(name = archived_post)]
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