You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rename module to database where appropriate (#277)
* clients connect to databases, not modules
* the name is for the database, not the module
* reducers are exposed by databases, not modules
* don't name clients "modules" too
* Modules have no state, the database has it
* more database instead of client connection
* databases are hosted, not modules
* users interact with databases, not modules
* fix typo
* Apply suggestions from code review
Co-authored-by: Tyler Cloutier <[email protected]>
* Apply suggestions from code review
Co-authored-by: Tyler Cloutier <[email protected]>
---------
Co-authored-by: Tyler Cloutier <[email protected]>
> Yes!Yourclientcanconstructasmany `DbConnection`ssimultaneouslyasitwantsto, eachofwhichwilloperateindependently.Ifyouwanttoconnecttotwomoduleswithdifferentschemas, use `spacetime generate` to include bindings for both of them in your client project.Note that SpacetimeDB may reject multiple concurrent connections to the same module by a single client.
316
+
> Yes!Yourclientcanconstructasmany `DbConnection`ssimultaneouslyasitwantsto, eachofwhichwilloperateindependently.Ifyouwanttoconnecttotwodatabaseswithdifferentschemas, use `spacetime generate` to include bindings for both of them in your client project.Note that SpacetimeDB may reject multiple concurrent connections to the same database by a single client.
317
317
318
318
## Tutorial pages
319
319
@@ -341,7 +341,7 @@ The first time a tutorial or series introduces a new type / function / method /
341
341
342
342
### Tutorial code
343
343
344
-
If the tutorial involves writing code, e.g.for a module or client, the tutorial should include the complete result code within its text.Ideally, it should be possible for a reader to copy and paste all the code blocks in the document into a file, effectively concatentating them together, and wind up with a coherent and runnable program.Sometimes this is not possible, e.g. because C# requires wrapping your whole file in a bunch of scopes.In this case, precede each code block with a sentence that describes where the reader is going to paste it.
344
+
If the tutorial involves writing code, e.g.for a module or client, the tutorial should include the complete result code within its text.Ideally, it should be possible for a reader to copy and paste all the code blocks in the document into a file, effectively concatenating them together, and wind up with a coherent and runnable program.Sometimes this is not possible, e.g. because C# requires wrapping your whole file in a bunch of scopes.In this case, precede each code block with a sentence that describes where the reader is going to paste it.
345
345
346
346
Include even uninteresting code, like imports!You can rush through these without spending too much time on them, but make sure that every line of code required to make the project work appears in the tutorial.
ssh ubuntu@<host> spacetime publish -s local --bin-path spacetime_module.wasm <module-name>
171
+
ssh ubuntu@<host> spacetime publish -s local --bin-path spacetime_module.wasm <database-name>
172
172
```
173
173
174
174
You could put the above commands into a shell script to make publishing to your server easier and faster. It's also possible to integrate a script like this into Github Actions to publish on some event (like a PR merging into master).
Copy file name to clipboardExpand all lines: docs/index.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -229,7 +229,7 @@ Clients are regular software applications that developers can choose how to depl
229
229
230
230
### Identity
231
231
232
-
A SpacetimeDB `Identity` identifies someone interacting with a module. It is a long lived, public, globally valid identifier that will always refer to the same end user, even across different connections.
232
+
A SpacetimeDB `Identity` identifies someone interacting with a database. It is a long lived, public, globally valid identifier that will always refer to the same end user, even across different connections.
233
233
234
234
A user's `Identity` is attached to every [reducer call](#reducer) they make, and you can use this to decide what they are allowed to do.
Copy file name to clipboardExpand all lines: docs/modules/c-sharp/index.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -841,13 +841,13 @@ This reducer can be used to configure any static data tables used by your module
841
841
842
842
### The `ClientConnected` reducer
843
843
844
-
This reducer is marked with `[SpacetimeDB.Reducer(ReducerKind.ClientConnected)]`. It is run when a client connects to the SpacetimeDB module. Their identity can be found in the sender value of the `ReducerContext`.
844
+
This reducer is marked with `[SpacetimeDB.Reducer(ReducerKind.ClientConnected)]`. It is run when a client connects to the SpacetimeDB database. Their identity can be found in the sender value of the `ReducerContext`.
845
845
846
846
If an error occurs in the reducer, the client will be disconnected.
847
847
848
848
### The `ClientDisconnected` reducer
849
849
850
-
This reducer is marked with `[SpacetimeDB.Reducer(ReducerKind.ClientDisconnected)]`. It is run when a client disconnects from the SpacetimeDB module. Their identity can be found in the sender value of the `ReducerContext`.
850
+
This reducer is marked with `[SpacetimeDB.Reducer(ReducerKind.ClientDisconnected)]`. It is run when a client disconnects from the SpacetimeDB database. Their identity can be found in the sender value of the `ReducerContext`.
851
851
852
852
If an error occurs in the disconnect reducer, the client is still recorded as disconnected.
853
853
@@ -1013,7 +1013,7 @@ namespace SpacetimeDB
1013
1013
1014
1014
Methods for writing to a private debug log. Log messages will include file andline numbers.
1015
1015
1016
-
Log outputs of a running module can be inspected using the `spacetime logs` command:
1016
+
Log outputs of a running database can be inspected using the `spacetime logs` command:
Copy file name to clipboardExpand all lines: docs/modules/c-sharp/quickstart.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -233,7 +233,7 @@ public static void ClientConnected(ReducerContext ctx)
233
233
}
234
234
```
235
235
236
-
Similarly, whenever a client disconnects, the module will execute the `OnDisconnect` event if it's registered with `ReducerKind.ClientDisconnected`. We'll use it to un-set the `Online` status of the `User` for the disconnected client.
236
+
Similarly, whenever a client disconnects, the database will execute the `OnDisconnect` event if it's registered with `ReducerKind.ClientDisconnected`. We'll use it to un-set the `Online` status of the `User` for the disconnected client.
237
237
238
238
Add the following code after the `OnConnect` handler:
You've just set up your first database in SpacetimeDB! You can find the full code for this client [in the C# server module example](https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/tree/master/examples~/quickstart-chat/server).
313
313
314
-
The next step would be to create a client module that interacts with this module. You can use any of SpacetimDB's supported client languages to do this. Take a look at the quick start guide for your client language of choice: [Rust](/docs/sdks/rust/quickstart), [C#](/docs/sdks/c-sharp/quickstart), or [TypeScript](/docs/sdks/typescript/quickstart).
314
+
The next step would be to create a client that interacts with this module. You can use any of SpacetimDB's supported client languages to do this. Take a look at the quick start guide for your client language of choice: [Rust](/docs/sdks/rust/quickstart), [C#](/docs/sdks/c-sharp/quickstart), or [TypeScript](/docs/sdks/typescript/quickstart).
315
315
316
316
If you are planning to use SpacetimeDB with the Unity game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1).
Copy file name to clipboardExpand all lines: docs/modules/rust/quickstart.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -182,15 +182,15 @@ You could extend the validation in `validate_message` in similar ways to `valida
182
182
183
183
## Set users' online status
184
184
185
-
Whenever a client connects, the module will run a special reducer, annotated with `#[reducer(client_connected)]`, if it's defined. By convention, it's named `client_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.
185
+
Whenever a client connects, the database will run a special reducer, annotated with `#[reducer(client_connected)]`, if it's defined. By convention, it's named `client_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.
186
186
187
187
We'll use `ctx.db.user().identity().find(ctx.sender)` to look up a `User` row for `ctx.sender`, if one exists. If we find one, we'll use `ctx.db.user().identity().update(..)` to overwrite it with a row that has `online: true`. If not, we'll use `ctx.db.user().insert(..)` to insert a new row for our new user. All three of these methods are generated by the `#[table(..)]` macro, with rows and behavior based on the row attributes. `ctx.db.user().find(..)` returns an `Option<User>`, because of the unique constraint from the `#[primary_key]` attribute. This means there will be either zero or one matching rows. If we used `try_insert` here it would return a `Result<(), UniqueConstraintViolation>` because of the same unique constraint. However, because we're already checking if there is a user with the given sender identity we know that inserting into this table will not fail. Therefore, we use `insert`, which automatically unwraps the result, simplifying the code. If we want to overwrite a `User` row, we need to do so explicitly using `ctx.db.user().identity().update(..)`.
188
188
189
189
To `server/src/lib.rs`, add the definition of the connect reducer:
190
190
191
191
```rust
192
192
#[reducer(client_connected)]
193
-
// Called when a client connects to the SpacetimeDB
193
+
// Called when a client connects to a SpacetimeDB database server
Similarly, whenever a client disconnects, the module will run the `#[reducer(client_disconnected)]` reducer if it's defined. By convention, it's named `client_disconnected`. We'll use it to un-set the `online` status of the `User` for the disconnected client.
211
+
Similarly, whenever a client disconnects, the database will run the `#[reducer(client_disconnected)]` reducer if it's defined. By convention, it's named `client_disconnected`. We'll use it to un-set the `online` status of the `User` for the disconnected client.
212
212
213
213
```rust
214
214
#[reducer(client_disconnected)]
215
-
// Called when a client disconnects from SpacetimeDB
215
+
// Called when a client disconnects from SpacetimeDB database server
You can find the full code for this module [in the SpacetimeDB module examples](https://github.com/clockworklabs/SpacetimeDB/tree/master/modules/quickstart-chat).
277
277
278
-
You've just set up your first database in SpacetimeDB! The next step would be to create a client module that interacts with this module. You can use any of SpacetimDB's supported client languages to do this. Take a look at the quickstart guide for your client language of choice: [Rust](/docs/sdks/rust/quickstart), [C#](/docs/sdks/c-sharp/quickstart), or [TypeScript](/docs/sdks/typescript/quickstart).
278
+
You've just set up your first database in SpacetimeDB! The next step would be to create a client that interacts with this module. You can use any of SpacetimDB's supported client languages to do this. Take a look at the quickstart guide for your client language of choice: [Rust](/docs/sdks/rust/quickstart), [C#](/docs/sdks/c-sharp/quickstart), or [TypeScript](/docs/sdks/typescript/quickstart).
279
279
280
280
If you are planning to use SpacetimeDB with the Unity game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1).
0 commit comments