Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

This repository contains the [Unity](https://unity.com/) SDK for SpacetimeDB. The SDK allows to interact with the database server and is prepared to work with code generated from a SpacetimeDB backend code.
This repository contains the C# and [Unity](https://unity.com/) SDKs for SpacetimeDB. The SDK allows to interact with the database server and is prepared to work with code generated from a SpacetimeDB backend code.

## Documentation

Expand Down
29 changes: 10 additions & 19 deletions examples~/quickstart/client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void PrintMessage(RemoteTables tables, Message message)

void Message_OnInsert(EventContext ctx, Message insertedValue)
{

if (ctx.Event is not Event<Reducer>.SubscribeApplied)
{
PrintMessage(ctx.Db, insertedValue);
Expand Down Expand Up @@ -123,25 +124,15 @@ void OnConnect(DbConnection conn, Identity identity, string authToken)
local_identity = identity;
AuthToken.SaveToken(authToken);

var subscriptions = 0;
Action<SubscriptionEventContext> waitForSubscriptions = (SubscriptionEventContext ctx) =>
{
// Note: callbacks are always invoked on the main thread, so you don't need to
// worry about thread synchronization or anything like that.
subscriptions += 1;

if (subscriptions == 2)
{
OnSubscriptionApplied(ctx);
}
};

var userSubscription = conn.SubscriptionBuilder()
.OnApplied(waitForSubscriptions)
.Subscribe("SELECT * FROM user");
var messageSubscription = conn.SubscriptionBuilder()
.OnApplied(waitForSubscriptions)
.Subscribe("SELECT * FROM message");
var subscription = conn.SubscriptionBuilder()
.OnApplied(OnSubscriptionApplied)
.Subscribe(new string[] {
"SELECT * FROM user",
"SELECT * FROM message",
// It is legal to have redundant subscriptions.
// However, keep in mind that data will be sent over the wire multiple times,
// once for each subscriptions. This can cause slowdowns if you aren't careful.
"SELECT * FROM message" });

// You can also use SubscribeToAllTables, but it should be avoided if you have any large tables:
// conn.SubscriptionBuilder().OnApplied(OnSubscriptionApplied).SubscribeToAllTables();
Expand Down
Loading