Skip to content

Commit c86e3da

Browse files
authored
Revert "Update docs for #[spacetimedb(table)] (#61)" (#62)
This reverts commit fce4df6.
1 parent fce4df6 commit c86e3da

File tree

5 files changed

+25
-31
lines changed

5 files changed

+25
-31
lines changed

docs/docs/modules/rust/index.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use spacetimedb::{spacetimedb, println};
3131
// This macro lets us interact with a SpacetimeDB table of Person rows.
3232
// We can insert and delete into, and query, this table by the collection
3333
// of functions generated by the macro.
34-
#[spacetimedb(table(public))]
34+
#[spacetimedb(table)]
3535
pub struct Person {
3636
name: String,
3737
}
@@ -88,12 +88,10 @@ Now we'll get into details on all the macro APIs SpacetimeDB provides, starting
8888

8989
### Defining tables
9090

91-
The `#[spacetimedb(table)]` is applied to a Rust struct with named fields.
92-
By default, tables are considered **private**. This means that they are only readable by the table owner, and by server module code.
93-
The `#[spacetimedb(table(public))]` macro makes a table public. **Public** tables are readable by all users, but can still only be modified by your server module code.
91+
`#[spacetimedb(table)]` takes no further arguments, and is applied to a Rust struct with named fields:
9492

9593
```rust
96-
#[spacetimedb(table(public))]
94+
#[spacetimedb(table)]
9795
struct Table {
9896
field1: String,
9997
field2: u32,
@@ -118,10 +116,10 @@ And common data structures:
118116
- `Option<T> where T: SpacetimeType`
119117
- `Vec<T> where T: SpacetimeType`
120118

121-
All `#[spacetimedb(table(...))]` types are `SpacetimeType`s, and accordingly, all of their fields have to be.
119+
All `#[spacetimedb(table)]` types are `SpacetimeType`s, and accordingly, all of their fields have to be.
122120

123121
```rust
124-
#[spacetimedb(table(public))]
122+
#[spacetimedb(table)]
125123
struct AnotherTable {
126124
// Fine, some builtin types.
127125
id: u64,
@@ -153,7 +151,7 @@ enum Serial {
153151
Once the table is created via the macro, other attributes described below can control more aspects of the table. For instance, a particular column can be indexed, or take on values of an automatically incremented counter. These are described in detail below.
154152

155153
```rust
156-
#[spacetimedb(table(public))]
154+
#[spacetimedb(table)]
157155
struct Person {
158156
#[unique]
159157
id: u64,
@@ -271,7 +269,7 @@ We'll work off these structs to see what functions SpacetimeDB generates:
271269
This table has a plain old column.
272270

273271
```rust
274-
#[spacetimedb(table(public))]
272+
#[spacetimedb(table)]
275273
struct Ordinary {
276274
ordinary_field: u64,
277275
}
@@ -280,7 +278,7 @@ struct Ordinary {
280278
This table has a unique column. Every row in the `Person` table must have distinct values of the `unique_field` column. Attempting to insert a row with a duplicate value will fail.
281279

282280
```rust
283-
#[spacetimedb(table(public))]
281+
#[spacetimedb(table)]
284282
struct Unique {
285283
// A unique column:
286284
#[unique]
@@ -293,7 +291,7 @@ This table has an automatically incrementing column. SpacetimeDB automatically p
293291
Only integer types can be `#[unique]`: `u8`, `u16`, `u32`, `u64`, `u128`, `i8`, `i16`, `i32`, `i64` and `i128`.
294292

295293
```rust
296-
#[spacetimedb(table(public))]
294+
#[spacetimedb(table)]
297295
struct Autoinc {
298296
#[autoinc]
299297
autoinc_field: u64,
@@ -303,7 +301,7 @@ struct Autoinc {
303301
These attributes can be combined, to create an automatically assigned ID usable for filtering.
304302

305303
```rust
306-
#[spacetimedb(table(public))]
304+
#[spacetimedb(table)]
307305
struct Identity {
308306
#[autoinc]
309307
#[unique]
@@ -377,7 +375,7 @@ fn insert_id() {
377375
Given a table, we can iterate over all the rows in it.
378376

379377
```rust
380-
#[spacetimedb(table(public))]
378+
#[spacetimedb(table)]
381379
struct Person {
382380
#[unique]
383381
id: u64,

docs/docs/modules/rust/quickstart.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ A SpacetimeDB module is code that gets compiled to WebAssembly and is uploaded t
66

77
Each SpacetimeDB module defines a set of tables and a set of reducers.
88

9-
Each table is defined as a Rust `struct` annotated with `#[spacetimedb(table(...))]`, where an instance represents a row, and each field represents a column.
10-
By default, tables are **private**. This means that they are only readable by the table owner, and by server module code.
11-
The `#[spacetimedb(table(public))]` macro makes a table public. **Public** tables are readable by all users, but can still only be modified by your server module code.
12-
13-
_Coming soon: We plan to add much more robust access controls than just `public` or `private`. Stay tuned!_
9+
Each table is defined as a Rust `struct` annotated with `#[spacetimedb(table)]`, where an instance represents a row, and each field represents a column.
1410

1511
A reducer is a function which traverses and updates the database. Each reducer call runs in its own transaction, and its updates to the database are only committed if the reducer returns successfully. In Rust, reducers are defined as functions annotated with `#[spacetimedb(reducer)]`, and may return a `Result<()>`, with an `Err` return aborting the transaction.
1612

@@ -71,7 +67,7 @@ For each `User`, we'll store their `Identity`, an optional name they can set to
7167
To `server/src/lib.rs`, add the definition of the table `User`:
7268

7369
```rust
74-
#[spacetimedb(table(public))]
70+
#[spacetimedb(table)]
7571
pub struct User {
7672
#[primarykey]
7773
identity: Identity,
@@ -85,7 +81,7 @@ For each `Message`, we'll store the `Identity` of the user who sent it, the `Tim
8581
To `server/src/lib.rs`, add the definition of the table `Message`:
8682

8783
```rust
88-
#[spacetimedb(table(public))]
84+
#[spacetimedb(table)]
8985
pub struct Message {
9086
sender: Identity,
9187
sent: Timestamp,
@@ -183,7 +179,7 @@ You could extend the validation in `validate_message` in similar ways to `valida
183179

184180
Whenever a client connects, the module will run a special reducer, annotated with `#[spacetimedb(connect)]`, if it's defined. By convention, it's named `identity_connected`. We'll use it to create a `User` record for the client if it doesn't yet exist, and to set its online status.
185181

186-
We'll use `User::filter_by_identity` to look up a `User` row for `ctx.sender`, if one exists. If we find one, we'll use `User::update_by_identity` to overwrite it with a row that has `online: true`. If not, we'll use `User::insert` to insert a new row for our new user. All three of these methods are generated by the `#[spacetimedb(table(...))]` attribute, with rows and behavior based on the row attributes. `filter_by_identity` returns an `Option<User>`, because the unique constraint from the `#[primarykey]` attribute means there will be either zero or one matching rows. `insert` returns a `Result<(), UniqueConstraintViolation>` because of the same unique constraint; if we want to overwrite a `User` row, we need to do so explicitly using `update_by_identity`.
182+
We'll use `User::filter_by_identity` to look up a `User` row for `ctx.sender`, if one exists. If we find one, we'll use `User::update_by_identity` to overwrite it with a row that has `online: true`. If not, we'll use `User::insert` to insert a new row for our new user. All three of these methods are generated by the `#[spacetimedb(table)]` attribute, with rows and behavior based on the row attributes. `filter_by_identity` returns an `Option<User>`, because the unique constraint from the `#[primarykey]` attribute means there will be either zero or one matching rows. `insert` returns a `Result<(), UniqueConstraintViolation>` because of the same unique constraint; if we want to overwrite a `User` row, we need to do so explicitly using `update_by_identity`.
187183

188184
To `server/src/lib.rs`, add the definition of the connect reducer:
189185

docs/docs/unity/part-2a-rust.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ use spacetimedb::{spacetimedb, Identity, SpacetimeType, ReducerContext};
2929
use log;
3030
```
3131

32-
Then we are going to start by adding the global `Config` table. Right now it only contains the "message of the day" but it can be extended to store other configuration variables. This also uses a couple of macros, like `#[spacetimedb(table(...))]` which you can learn more about in our [Rust module reference](/docs/modules/rust) (including making your tables `private`!). Simply put, this just tells SpacetimeDB to create a table which uses this struct as the schema for the table.
32+
Then we are going to start by adding the global `Config` table. Right now it only contains the "message of the day" but it can be extended to store other configuration variables. This also uses a couple of macros, like `#[spacetimedb(table)]` which you can learn more about in our [Rust module reference](/docs/modules/rust). Simply put, this just tells SpacetimeDB to create a table which uses this struct as the schema for the table.
3333

3434
**Append to the bottom of lib.rs:**
3535

3636
```rust
3737
// We're using this table as a singleton, so there should typically only be one element where the version is 0.
38-
#[spacetimedb(table(public))]
38+
#[spacetimedb(table)]
3939
#[derive(Clone)]
4040
pub struct Config {
4141
#[primarykey]
@@ -44,7 +44,7 @@ pub struct Config {
4444
}
4545
```
4646

47-
Next, we're going to define a new `SpacetimeType` called `StdbVector3` which we're going to use to store positions. The difference between a `#[derive(SpacetimeType)]` and a `#[spacetimedb(table(...))]` is that tables actually store data, whereas the deriving `SpacetimeType` just allows you to create a new column of that type in a SpacetimeDB table. Therefore, `StdbVector3` is not, itself, a table.
47+
Next, we're going to define a new `SpacetimeType` called `StdbVector3` which we're going to use to store positions. The difference between a `#[derive(SpacetimeType)]` and a `#[spacetimedb(table)]` is that tables actually store data, whereas the deriving `SpacetimeType` just allows you to create a new column of that type in a SpacetimeDB table. Therefore, `StdbVector3` is not, itself, a table.
4848

4949
**Append to the bottom of lib.rs:**
5050

@@ -64,7 +64,7 @@ Now we're going to create a table which actually uses the `StdbVector3` that we
6464
// This stores information related to all entities in our game. In this tutorial
6565
// all entities must at least have an entity_id, a position, a direction and they
6666
// must specify whether or not they are moving.
67-
#[spacetimedb(table(public))]
67+
#[spacetimedb(table)]
6868
#[derive(Clone)]
6969
pub struct EntityComponent {
7070
#[primarykey]
@@ -87,7 +87,7 @@ Next, we will define the `PlayerComponent` table. The `PlayerComponent` table is
8787
// All players have this component and it associates an entity with the user's
8888
// Identity. It also stores their username and whether or not they're logged in.
8989
#[derive(Clone)]
90-
#[spacetimedb(table(public))]
90+
#[spacetimedb(table)]
9191
pub struct PlayerComponent {
9292
// An entity_id that matches an entity_id in the `EntityComponent` table.
9393
#[primarykey]
@@ -264,7 +264,7 @@ First lets add a new `ChatMessage` table to the SpacetimeDB module. Add the foll
264264
**Append to the bottom of server/src/lib.rs:**
265265

266266
```rust
267-
#[spacetimedb(table(public))]
267+
#[spacetimedb(table)]
268268
pub struct ChatMessage {
269269
// The primary key for this table will be auto-incremented
270270
#[primarykey]

docs/docs/unity/part-2b-c-sharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using SpacetimeDB.Module;
3030
using static SpacetimeDB.Runtime;
3131
```
3232

33-
Then we are going to start by adding the global `Config` table. Right now it only contains the "message of the day" but it can be extended to store other configuration variables. This also uses a couple of attributes, like `[SpacetimeDB.Table]` which you can learn more about in our [C# module reference](/docs/modules/c-sharp). Simply put, this just tells SpacetimeDB to create a table which uses this struct as the schema for the table.
33+
Then we are going to start by adding the global `Config` table. Right now it only contains the "message of the day" but it can be extended to store other configuration variables. This also uses a couple of macros, like `#[spacetimedb(table)]` which you can learn more about in our [C# module reference](/docs/modules/c-sharp). Simply put, this just tells SpacetimeDB to create a table which uses this struct as the schema for the table.
3434

3535
**Append to the bottom of lib.cs:**
3636

docs/docs/unity/part-4.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub enum ResourceNodeType {
3434
Iron,
3535
}
3636

37-
#[spacetimedb(table(public))]
37+
#[spacetimedb(table)]
3838
#[derive(Clone)]
3939
pub struct ResourceNodeComponent {
4040
#[primarykey]
@@ -48,7 +48,7 @@ pub struct ResourceNodeComponent {
4848
Because resource nodes never move, the `MobileEntityComponent` is overkill. Instead, we will add a new entity component named `StaticLocationComponent` that only stores the position and rotation.
4949

5050
```rust
51-
#[spacetimedb(table(public))]
51+
#[spacetimedb(table)]
5252
#[derive(Clone)]
5353
pub struct StaticLocationComponent {
5454
#[primarykey]
@@ -62,7 +62,7 @@ pub struct StaticLocationComponent {
6262
3. We are also going to add a couple of additional column to our Config table. `map_extents` let's our spawner know where it can spawn the nodes. `num_resource_nodes` is the maximum number of nodes to spawn on the map. Update the config table in lib.rs.
6363

6464
```rust
65-
#[spacetimedb(table(public))]
65+
#[spacetimedb(table)]
6666
pub struct Config {
6767
// Config is a global table with a single row. This table will be used to
6868
// store configuration or global variables

0 commit comments

Comments
 (0)