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
* doc: Onboarding impr, fixes, consistency, cleanup
refactor: Whats next cleanup, +unity, -bloat
Removed redundant text while there
refactor: Unity quickstart fixes, impr, prettify
refactor: Unity pt1 fixes, impr, prettify
fix(README): Rm "see test edits below" ref
* !exists
refactor(minor): General onboarding cleanup
* Shorter, prettier, consistent
fix(sdks/c#): Broken unitypackage url
feat(sdks/c#): Add OneTimeQuery api ref
* doc: Onboarding impr, fixes, consistency, cleanup
* fix: Rm redundant 'module_bindings' mention
* fix: Floating period, "arbitrary", "important":
- PR review change requests
- Additionally: hasUpdatedRecently fix and reformatting
* fix: Mentioned FilterBy, used FindBy
- Used FindBy since that was what the tutorial used, and also looking for a single Identity.
- Note: There may be a similar rust discrepancy in the Unity pt1 tutorial. It'll work with Filter, but just simply less consistent. Holding off on that since my Rust syntax knowledge !exists.
* fix(Unity-pt1): Rm copy+paste redundant comments
* Duplicate comments found both above and within funcs
* fix(unity): Rm unused using statement +merged info
* Removed `System.Runtime.CompilerServices`
* SpacetimeDB.Module seems to already include this (merged the info)
* refactor(minor): Code spacing for grouping/clarity
* feat: 'Standalone mode runs in foreground' memo
* At general quickstart for `spacetime start`
* refactor(unity-pt1): Standalone mode foreground memo
* Also, removed the "speed" loss mention of C#
* fix(syntaxErr): Fix err, keep FilterBy, handle null
- After a verbose discussion, we will eventually swap to FindBy for single-result queries, but not in this PR.
- For now, the syntax err is fixed by making the var nullable and suffixing a LINQ FirstOrDefault(). Approved by Tyler in Discord.
- We never *actually* created a player in the tutorial. This creates the player. Approved by Tyler in Discord.
* fix: Remote player `is null` check removal
Copy file name to clipboardExpand all lines: docs/modules/c-sharp/index.md
+3Lines changed: 3 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -42,6 +42,7 @@ static partial class Module
42
42
{
43
43
// We can skip (or explicitly set to zero) auto-incremented fields when creating new rows.
44
44
varperson=newPerson { Name=name, Age=age };
45
+
45
46
// `Insert()` method is auto-generated and will insert the given row into the table.
46
47
person.Insert();
47
48
// After insertion, the auto-incremented fields will be populated with their actual values.
@@ -211,8 +212,10 @@ public partial struct Person
211
212
212
213
// Finds a row in the table with the given value in the `Id` column and returns it, or `null` if no such row exists.
213
214
publicstaticPerson? FindById(intid);
215
+
214
216
// Deletes a row in the table with the given value in the `Id` column and returns `true` if the row was found and deleted, or `false` if no such row exists.
215
217
publicstaticboolDeleteById(intid);
218
+
216
219
// Updates a row in the table with the given value in the `Id` column and returns `true` if the row was found and updated, or `false` if no such row exists.
Copy file name to clipboardExpand all lines: docs/modules/c-sharp/quickstart.md
+29-8Lines changed: 29 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,18 @@ If you haven't already, start by [installing SpacetimeDB](/install). This will i
16
16
17
17
## Install .NET 8
18
18
19
-
Next we need to [install .NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) so that we can build and publish our module. .NET 8.0 is the earliest to have the `wasi-experimental` workload that we rely on.
19
+
Next we need to [install .NET 8 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) so that we can build and publish our module.
20
+
21
+
You may already have .NET 8 and can be checked:
22
+
```bash
23
+
dotnet --list-sdks
24
+
```
25
+
26
+
.NET 8.0 is the earliest to have the `wasi-experimental` workload that we rely on, but requires manual activation:
27
+
28
+
```bash
29
+
dotnet workload install wasi-experimental
30
+
```
20
31
21
32
## Project structure
22
33
@@ -35,7 +46,11 @@ spacetime init --lang csharp server
35
46
36
47
## Declare imports
37
48
38
-
`spacetime init` should have pre-populated `server/Lib.cs` with a trivial module. Clear it out, so we can write a module that's still pretty simple: a bare-bones chat server.
49
+
`spacetime init` generated a few files:
50
+
51
+
1. Open `server/StdbModule.csproj` to generate a .sln file for intellisense/validation support.
52
+
2. Open `server/Lib.cs`, a trivial module.
53
+
3. Clear it out, so we can write a new module that's still pretty simple: a bare-bones chat server.
39
54
40
55
To the top of `server/Lib.cs`, add some imports we'll be using:
41
56
@@ -45,8 +60,10 @@ using SpacetimeDB.Module;
45
60
usingstaticSpacetimeDB.Runtime;
46
61
```
47
62
48
-
-`System.Runtime.CompilerServices` allows us to use the `ModuleInitializer` attribute, which we'll use to register our `OnConnect` and `OnDisconnect` callbacks.
49
-
-`SpacetimeDB.Module` contains the special attributes we'll use to define our module.
63
+
-`System.Runtime.CompilerServices`
64
+
-`SpacetimeDB.Module`
65
+
- Contains the special attributes we'll use to define our module.
66
+
- Allows us to use the `ModuleInitializer` attribute, which we'll use to register our `OnConnect` and `OnDisconnect` callbacks.
50
67
-`SpacetimeDB.Runtime` contains the raw API bindings SpacetimeDB uses to communicate with the database.
51
68
52
69
We also need to create our static module class which all of the module code will live in. In `server/Lib.cs`, add:
@@ -184,7 +201,7 @@ You could extend the validation in `ValidateMessage` in similar ways to `Validat
184
201
185
202
In C# modules, you can register for `Connect` and `Disconnect` events by using a special `ReducerKind`. We'll use the `Connect` event to create a `User` record for the client if it doesn't yet exist, and to set its online status.
186
203
187
-
We'll use `User.FilterByIdentity` to look up a `User` row for `dbEvent.Sender`, if one exists. If we find one, we'll use `User.UpdateByIdentity` 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. `FilterByIdentity` returns a nullable `User`, because the unique constraint from the `[SpacetimeDB.Column(ColumnAttrs.PrimaryKey)]` attribute means there will be either zero or one matching rows. `Insert` will throw an exception if the insert violates this constraint; if we want to overwrite a `User` row, we need to do so explicitly using `UpdateByIdentity`.
204
+
We'll use `User.FindByIdentity` to look up a `User` row for `dbEvent.Sender`, if one exists. If we find one, we'll use `User.UpdateByIdentity` 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. `FindByIdentity` returns a nullable `User`, because the unique constraint from the `[SpacetimeDB.Column(ColumnAttrs.PrimaryKey)]` attribute means there will be either zero or one matching rows. `Insert` will throw an exception if the insert violates this constraint; if we want to overwrite a `User` row, we need to do so explicitly using `UpdateByIdentity`.
188
205
189
206
In `server/Lib.cs`, add the definition of the connect reducer to the `Module` class:
190
207
@@ -235,7 +252,7 @@ public static void OnDisconnect(DbEventArgs dbEventArgs)
235
252
else
236
253
{
237
254
// User does not exist, log warning
238
-
Log($"Warning: No user found for disconnected client.");
255
+
Log("Warning: No user found for disconnected client.");
239
256
}
240
257
}
241
258
```
@@ -250,12 +267,16 @@ From the `quickstart-chat` directory, run:
250
267
spacetime publish --project-path server <module-name>
251
268
```
252
269
270
+
```bash
271
+
npm i wasm-opt -g
272
+
```
273
+
253
274
## Call Reducers
254
275
255
276
You can use the CLI (command line interface) to run reducers. The arguments to the reducer are passed in JSON format.
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 quick start guide for your client language of choice: [Rust](/docs/languages/rust/rust-sdk-quickstart-guide), [C#](/docs/languages/csharp/csharp-sdk-quickstart-guide), [TypeScript](/docs/languages/typescript/typescript-sdk-quickstart-guide) or [Python](/docs/languages/python/python-sdk-quickstart-guide).
290
311
291
-
If you are planning to use SpacetimeDB with the Unity3d game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1) or check out our example game, [BitcraftMini](/docs/unity/part-3).
312
+
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) or check out our example game, [BitcraftMini](/docs/unity/part-3).
Copy file name to clipboardExpand all lines: docs/modules/rust/quickstart.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -269,4 +269,4 @@ You can find the full code for this module [in the SpacetimeDB module examples](
269
269
270
270
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), [TypeScript](/docs/sdks/typescript/quickstart) or [Python](/docs/sdks/python/quickstart).
271
271
272
-
If you are planning to use SpacetimeDB with the Unity3d game engine, you can skip right to the [Unity Comprehensive Tutorial](/docs/unity/part-1) or check out our example game, [BitcraftMini](/docs/unity/part-3).
272
+
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) or check out our example game, [BitcraftMini](/docs/unity/part-3).
To install the SpacetimeDB SDK into a Unity project, download the SpacetimeDB SDK from the following link.
68
+
To install the SpacetimeDB SDK into a Unity project, [download the SpacetimeDB SDK](https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/releases/latest), packaged as a `.unitypackage`.
In Unity navigate to the `Assets > Import Package > Custom Package` menu in the menu bar. Select your `SpacetimeDB.Unity.Comprehensive.Tutorial.unitypackage` file and leave all folders checked.
70
71
71
-
In Unity navigate to the `Assets > Import Package > Custom Package...` menu in the menu bar. Select your `SpacetimeDBUnitySDK.unitypackage` file and leave all folders checked.
72
-
73
-
(See also the [Unity Tutorial](/docs/unity/part-1).)
72
+
(See also the [Unity Tutorial](/docs/unity/part-1))
The SDK maintains a local view of the database called the "client cache". This cache contains whatever rows are selected via a call to [`SpacetimeDBClient.Subscribe`](#method-spacetimedbclientsubscribe). These rows are represented in the SpacetimeDB .Net SDK as instances of [`SpacetimeDB.Types.{TABLE}`](#class-table).
0 commit comments