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
Copy file name to clipboardExpand all lines: packages/sdk/README.md
+29-43Lines changed: 29 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -12,68 +12,54 @@ The SDK is an NPM package, thus you can use your package manager of choice like
12
12
npm install --save @clockworklabs/spacetimedb-sdk
13
13
```
14
14
15
-
You can use the package in the browser, using a bundler like webpack of vite, and in terminal applications
15
+
You can use the package in the browser, using a bundler like vite/parcel/rsbuild, in server-side applications like NodeJS, Deno, Bun and in Cloudflare Workers.
16
16
17
-
> NOTE: For usage in NodeJS 18-21, you need to install the `undici` package as a peer dependency as well: `npm install @clockworklabs/spacetimedb-sdk undici`. Node 22 and later are supported out of the box.
17
+
> NOTE: For usage in NodeJS 18-21, you need to install the `undici` package as a peer dependency: `npm install @clockworklabs/spacetimedb-sdk undici`. Node 22 and later are supported out of the box.
18
18
19
19
### Usage
20
20
21
-
In order to connect to a database you have to create a new client:
21
+
In order to connect to a database you have to generate module bindings for your database.
If for some reason you need to disconnect the client:
36
48
37
49
```ts
38
-
client.disconnect();
39
-
```
40
-
41
-
This will connect to a database instance without a specified identity. If you want to persist an identity fetched on connection you can register an `onConnect` callback, which will receive a new assigned identity as an argument:
42
-
43
-
```ts
44
-
client.onConnect((identity:string) => {
45
-
console.log(identity);
46
-
console.log(client.token);
47
-
});
48
-
```
49
-
50
-
You may also pass credentials as an optional third argument:
51
-
52
-
```ts
53
-
let credentials = { identity: '<identity>', token: '<token>' };
54
-
let client =newSpacetimeDBClient(
55
-
'spacetimedb.com/spacetimedb',
56
-
'<db-name>',
57
-
credentials
58
-
);
59
-
```
60
-
61
-
Typically, you will use the SDK with types generated from a backend DB service. For example, given a component named `Player` you can subscribe to player updates by registering the component:
62
-
63
-
```ts
64
-
client.registerComponent(Player, 'Player');
50
+
connection.disconnect();
65
51
```
66
52
67
-
Then you will be able to register callbacks on insert and delete events, for example:
53
+
Typically, you will use the SDK with types generated from a backend DB service. For example, given a table named `Player` you can subscribe to player updates like this:
68
54
69
55
```ts
70
-
Player.onInsert((newPlayer:Player) => {
71
-
console.log(newPlayer);
56
+
connection.db.player.onInsert((ctx, player) => {
57
+
console.log(player);
72
58
});
73
59
```
74
60
75
61
Given a reducer called `CreatePlayer` you can call it using a call method:
0 commit comments