Skip to content

Commit 15b4241

Browse files
authored
Updated with corrected table names to lower case, for compatibility w… (#195)
Updated with corrected table names to lower case, for compatibility with other quickstart-chat languages. Updated with additional changes in clockworklabs/com.clockworklabs.spacetimedbsdk#258
1 parent e5e885c commit 15b4241

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

docs/modules/c-sharp/quickstart.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ For each `User`, we'll store their `Identity`, an optional name they can set to
8282
In `server/Lib.cs`, add the definition of the table `User` to the `Module` class:
8383

8484
```csharp
85-
[Table(Name = "User", Public = true)]
85+
[Table(Name = "user", Public = true)]
8686
public partial class User
8787
{
8888
[PrimaryKey]
@@ -97,11 +97,11 @@ For each `Message`, we'll store the `Identity` of the user who sent it, the `Tim
9797
In `server/Lib.cs`, add the definition of the table `Message` to the `Module` class:
9898

9999
```csharp
100-
[Table(Name = "Message", Public = true)]
100+
[Table(Name = "message", Public = true)]
101101
public partial class Message
102102
{
103103
public Identity Sender;
104-
public long Sent;
104+
public Timestamp Sent;
105105
public string Text = "";
106106
}
107107
```
@@ -122,11 +122,11 @@ public static void SetName(ReducerContext ctx, string name)
122122
{
123123
name = ValidateName(name);
124124

125-
var user = ctx.Db.User.Identity.Find(ctx.Sender);
125+
var user = ctx.Db.user.Identity.Find(ctx.Sender);
126126
if (user is not null)
127127
{
128128
user.Name = name;
129-
ctx.Db.User.Identity.Update(user);
129+
ctx.Db.user.Identity.Update(user);
130130
}
131131
}
132132
```
@@ -165,12 +165,12 @@ public static void SendMessage(ReducerContext ctx, string text)
165165
{
166166
text = ValidateMessage(text);
167167
Log.Info(text);
168-
ctx.Db.Message.Insert(
168+
ctx.Db.message.Insert(
169169
new Message
170170
{
171171
Sender = ctx.Sender,
172172
Text = text,
173-
Sent = ctx.Timestamp.MicrosecondsSinceUnixEpoch,
173+
Sent = ctx.Timestamp,
174174
}
175175
);
176176
}
@@ -210,20 +210,20 @@ In `server/Lib.cs`, add the definition of the connect reducer to the `Module` cl
210210
public static void ClientConnected(ReducerContext ctx)
211211
{
212212
Log.Info($"Connect {ctx.Sender}");
213-
var user = ctx.Db.User.Identity.Find(ctx.Sender);
213+
var user = ctx.Db.user.Identity.Find(ctx.Sender);
214214

215215
if (user is not null)
216216
{
217217
// If this is a returning user, i.e., we already have a `User` with this `Identity`,
218218
// set `Online: true`, but leave `Name` and `Identity` unchanged.
219219
user.Online = true;
220-
ctx.Db.User.Identity.Update(user);
220+
ctx.Db.user.Identity.Update(user);
221221
}
222222
else
223223
{
224224
// If this is a new user, create a `User` object for the `Identity`,
225225
// which is online, but hasn't set a name.
226-
ctx.Db.User.Insert(
226+
ctx.Db.user.Insert(
227227
new User
228228
{
229229
Name = null,
@@ -243,13 +243,13 @@ Add the following code after the `OnConnect` handler:
243243
[Reducer(ReducerKind.ClientDisconnected)]
244244
public static void ClientDisconnected(ReducerContext ctx)
245245
{
246-
var user = ctx.Db.User.Identity.Find(ctx.Sender);
246+
var user = ctx.Db.user.Identity.Find(ctx.Sender);
247247

248248
if (user is not null)
249249
{
250250
// This user should exist, so set `Online: false`.
251251
user.Online = false;
252-
ctx.Db.User.Identity.Update(user);
252+
ctx.Db.user.Identity.Update(user);
253253
}
254254
else
255255
{
@@ -311,6 +311,8 @@ spacetime sql quickstart-chat "SELECT * FROM Message"
311311

312312
## What's next?
313313

314-
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/sdks/rust/quickstart), [C#](/docs/sdks/c-sharp/quickstart), or [TypeScript](/docs/sdks/typescript/quickstart).
314+
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).
315+
316+
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).
315317

316318
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).

docs/sdks/c-sharp/quickstart.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ using SpacetimeDB.Types;
7171
using System.Collections.Concurrent;
7272
```
7373

74-
We will also need to create some global variables that will be explained when we use them later.
74+
We will also need to create some global variables. We'll cover the `Identity` later in the `Save credentials` section. Later we'll also be setting up a second thread for handling user input. In the `Process thread` section we'll use this in the `ConcurrentQueue` to store the commands for that thread.
7575

7676
To `Program.cs`, add:
7777

@@ -153,7 +153,7 @@ DbConnection ConnectToDB()
153153
.WithToken(AuthToken.Token)
154154
.OnConnect(OnConnected)
155155
.OnConnectError(OnConnectError)
156-
.OnDisconnect(OnDisconnect)
156+
.OnDisconnect(OnDisconnected)
157157
.Build();
158158
return conn;
159159
}
@@ -198,12 +198,14 @@ To `Program.cs`, add:
198198

199199
```csharp
200200
/// Our `OnDisconnect` callback: print a note, then exit the process.
201-
void OnDisconnect(DbConnection conn, Exception? e)
201+
void OnDisconnected(DbConnection conn, Exception? e)
202202
{
203203
if (e != null)
204204
{
205205
Console.Write($"Disconnected abnormally: {e}");
206-
} else {
206+
}
207+
else
208+
{
207209
Console.Write($"Disconnected normally.");
208210
}
209211
}
@@ -319,6 +321,9 @@ To `Program.cs`, add:
319321
/// Our `Message.OnInsert` callback: print new messages.
320322
void Message_OnInsert(EventContext ctx, Message insertedValue)
321323
{
324+
// We are filtering out messages inserted during the subscription being applied,
325+
// since we will be printing those in the OnSubscriptionApplied callback,
326+
// where we will be able to first sort the messages before printing.
322327
if (ctx.Event is not Event<Reducer>.SubscribeApplied)
323328
{
324329
PrintMessage(ctx.Db, insertedValue);
@@ -551,7 +556,7 @@ dotnet run --project client
551556

552557
Congratulations! You've built a simple chat app using SpacetimeDB.
553558

554-
You can find the full code for this client [in the C# client SDK's examples](https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/tree/master/examples~/quickstart/client).
559+
You can find the full code for this client [in the C# client SDK's examples](https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/tree/master/examples~/quickstart-chat/client).
555560

556561
Check out the [C# client SDK Reference](/docs/sdks/c-sharp) for a more comprehensive view of the SpacetimeDB C# client SDK.
557562

0 commit comments

Comments
 (0)