From 81b4fb8a52efd7aba54cbed1d94343341bdea939 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 26 Nov 2024 17:19:18 +0000 Subject: [PATCH 1/3] Describe how to define multiple tables with the same type Fixes #90. --- docs/modules/c-sharp/index.md | 11 +++++++++++ docs/modules/rust/index.md | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/docs/modules/c-sharp/index.md b/docs/modules/c-sharp/index.md index f6763fc..5d5d586 100644 --- a/docs/modules/c-sharp/index.md +++ b/docs/modules/c-sharp/index.md @@ -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. diff --git a/docs/modules/rust/index.md b/docs/modules/rust/index.md index 24fa82b..c921e12 100644 --- a/docs/modules/rust/index.md +++ b/docs/modules/rust/index.md @@ -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>`. From a53916411e4c8fba83b4b25be2d054d41621959f Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 26 Nov 2024 17:19:52 +0000 Subject: [PATCH 2/3] Follow C# naming conventions --- docs/modules/c-sharp/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/modules/c-sharp/index.md b/docs/modules/c-sharp/index.md index 5d5d586..4fcf61e 100644 --- a/docs/modules/c-sharp/index.md +++ b/docs/modules/c-sharp/index.md @@ -256,8 +256,8 @@ 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)] +[SpacetimeDB.Table(Name = "Posts", Public = true)] +[SpacetimeDB.Table(Name = "ArchivedPosts", Public = false)] public partial struct Post { public string Title; public string Body; From 2670241b0b9e401720e304b8a2bf74375479d4d9 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Tue, 26 Nov 2024 18:14:24 +0000 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Phoebe Goldman --- docs/modules/c-sharp/index.md | 4 ++-- docs/modules/rust/index.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/modules/c-sharp/index.md b/docs/modules/c-sharp/index.md index 4fcf61e..2c31bb1 100644 --- a/docs/modules/c-sharp/index.md +++ b/docs/modules/c-sharp/index.md @@ -256,8 +256,8 @@ 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 = "ArchivedPosts", Public = false)] +[SpacetimeDB.Table(Name = "Post", Public = true)] +[SpacetimeDB.Table(Name = "ArchivedPost", Public = false)] public partial struct Post { public string Title; public string Body; diff --git a/docs/modules/rust/index.md b/docs/modules/rust/index.md index c921e12..dba75ab 100644 --- a/docs/modules/rust/index.md +++ b/docs/modules/rust/index.md @@ -168,8 +168,8 @@ 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)] +#[table(name = post, public)] +#[table(name = archived_post)] struct Post { title: String, body: String,