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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions skills/csharp-server/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The complete set of column attributes:
```csharp
[PrimaryKey] // primary key
[AutoInc] // auto-increment (use 0 as placeholder on insert)
[Unique] // unique constraint
[Unique] // unique constraint; indexes the column, enables .Find()
[SpacetimeDB.Index.BTree] // btree index (enables .Filter() on this column)
```

Expand Down Expand Up @@ -127,9 +127,10 @@ public static void DoReset(ReducerContext ctx) { ... }
## DB Operations

```csharp
ctx.Db.Entity.Insert(new Entity { Name = "Sample" }); // Insert
var row = ctx.Db.Entity.Insert(new Entity { Name = "Sample" }); // Insert; returns the row with AutoInc fields assigned
ctx.Db.Entity.Id.Find(entityId); // Find by PK → Entity? (nullable)
ctx.Db.Entity.Identity.Find(ctx.Sender); // Find by unique column → Entity?
if (ctx.Db.Entity.Id.Find(entityId) is { } entity) { ... } // unwrap Entity? before member access
ctx.Db.Item.AuthorId.Filter(authorId); // Filter by index → IEnumerable<Item>
ctx.Db.Entity.Iter(); // All rows → IEnumerable<Entity>
ctx.Db.Entity.Count; // Count rows
Expand Down Expand Up @@ -191,7 +192,7 @@ var expiry = ctx.Timestamp + new TimeDuration(delayMicros);
int roll = ctx.Rng.Next(1, 7); // [1, 7): inclusive 1, exclusive 7
double f = ctx.Rng.NextDouble(); // [0.0, 1.0)

// Client: Timestamp → milliseconds since epoch
// Timestamp → milliseconds since epoch
timestamp.MicrosecondsSinceUnixEpoch / 1000
```

Expand Down
2 changes: 2 additions & 0 deletions skills/typescript-server/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ Do not construct `Identity` values from strings (e.g. `'hex' as Identity`): seri
## Scheduled Tables

```typescript
import { ScheduleAt } from 'spacetimedb'; // ScheduleAt comes from the root package

const tick_timer = table({
name: 'tick_timer',
scheduled: (): any => tick, // (): any => breaks circular dep
Expand Down
1 change: 1 addition & 0 deletions tools/xtask-llm-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ workspace = true
spacetimedb.workspace = true
spacetimedb-guard.workspace = true
spacetimedb-data-structures.workspace = true
spacetimedb-lib.workspace = true

anyhow.workspace = true
serde.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { schema, table, t } from 'spacetimedb/server';

const userInternal = table({
const user_internal = table({
name: 'user_internal',
}, {
id: t.u64().primaryKey().autoInc(),
Expand All @@ -9,27 +9,27 @@ const userInternal = table({
passwordHash: t.string(),
});

const userPublic = table({
const user_public = table({
name: 'user_public',
public: true,
}, {
id: t.u64().primaryKey(),
name: t.string(),
});

const spacetimedb = schema({ userInternal, userPublic });
const spacetimedb = schema({ user_internal, user_public });
export default spacetimedb;

export const register_user = spacetimedb.reducer(
{ name: t.string(), email: t.string(), passwordHash: t.string() },
(ctx, { name, email, passwordHash }) => {
const internal = ctx.db.userInternal.insert({
const internal = ctx.db.user_internal.insert({
id: 0n,
name,
email,
passwordHash,
});
ctx.db.userPublic.insert({
ctx.db.user_public.insert({
id: internal.id,
name,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Write a SpacetimeDB backend module in TypeScript that defines a private table for sensitive data and a public table for client-visible data, with a reducer that copies safe fields from private to public.

TABLES
- userInternal
- user_internal
- private table (do not set public: true)
- Fields:
- id: number (u64, primary key, autoInc)
- name: string
- email: string
- passwordHash: string

- userPublic
- user_public
- public table (set public: true)
- Fields:
- id: number (u64, primary key)
- name: string

REDUCERS
- register_user(ctx, { name: string, email: string, passwordHash: string })
- Insert into userInternal (id: 0n for autoInc)
- Also insert into userPublic with just the id and name (safe fields only)
- Insert into user_internal (id: 0n for autoInc)
- Also insert into user_public with just the id and name (safe fields only)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { schema, table, t } from 'spacetimedb/server';

const emptyTable = table({ name: 'empty_table' }, { id: t.i32().primaryKey() });
const empty_table = table({ name: 'empty_table' }, { id: t.i32().primaryKey() });

const spacetimedb = schema({ emptyTable });
const spacetimedb = schema({ empty_table });
export default spacetimedb;

export const emptyReducerNoArgs = spacetimedb.reducer({}, ctx => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in TypeScript that defines a table and these five empty reducers.

TABLES
- emptyTable
- empty_table
- Fields:
- id: number (i32, primary key)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { ScheduleAt } from 'spacetimedb';
import { table, schema, t } from 'spacetimedb/server';

const tickTimer = table({
const tick_timer = table({
name: 'tick_timer',
scheduled: (): any => tick,
}, {
scheduledId: t.u64().primaryKey().autoInc(),
scheduledAt: t.scheduleAt(),
});

const spacetimedb = schema({ tickTimer });
const spacetimedb = schema({ tick_timer });
export default spacetimedb;

export const tick = spacetimedb.reducer({ timer: tickTimer.rowType }, (ctx, { timer }) => {
export const tick = spacetimedb.reducer({ timer: tick_timer.rowType }, (ctx, { timer }) => {
});

export const init = spacetimedb.init(ctx => {
ctx.db.tickTimer.insert({
ctx.db.tick_timer.insert({
scheduledId: 0n,
scheduledAt: ScheduleAt.interval(50_000n),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Write a SpacetimeDB backend module in TypeScript that defines a scheduled table and a scheduled reducer.

TABLE
- tickTimer
- tick_timer
- Fields:
- scheduledId: bigint (u64, primary key, auto-increment)
- scheduledAt: ScheduleAt
- Scheduled: tick reducer, interval of 50ms

REDUCERS
- tick: scheduled reducer that receives the tickTimer row
- tick: scheduled reducer that receives the tick_timer row
- init: insert initial scheduled row with 50ms interval
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static partial class Module
{
[Table(Accessor = "User")]
[Table(Accessor = "User", Public = true)]
public partial struct User
{
[PrimaryKey] public int Id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use spacetimedb::{reducer, table, ReducerContext, Table};

#[table(accessor = user)]
#[table(accessor = user, public)]
pub struct User {
#[primary_key]
pub id: i32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { table, schema, t } from 'spacetimedb/server';
const user = table(
{
name: 'user',
public: true,
},
{
id: t.i32().primaryKey(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in C# that defines one table and a reducer that inserts a row.

TABLE
- User
- User (public)
- Struct: User
- Fields:
- Id: int (primary key)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in Rust that defines one table and a reducer that inserts a row.

TABLE
- user
- user (public)
- Struct: User
- Fields:
- id: i32 (primary key)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in TypeScript that defines one table and a reducer that inserts a row.

TABLE
- user
- user (public)
- Fields:
- id: number (i32, primary key)
- name: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static partial class Module
{
[Table(Accessor = "User")]
[Table(Accessor = "User", Public = true)]
public partial struct User
{
[PrimaryKey, AutoInc] public ulong Id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use spacetimedb::{reducer, table, ReducerContext, Table};

#[table(accessor = user)]
#[table(accessor = user, public)]
pub struct User {
#[primary_key]
#[auto_inc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { table, schema, t } from 'spacetimedb/server';
const user = table(
{
name: 'user',
public: true,
},
{
id: t.u64().primaryKey().autoInc(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in C# that defines one table and two reducers: one that inserts a row and one that updates a row.

TABLE
- User
- User (public)
- Struct: User
- Fields:
- Id: ulong (primary key, auto-increment)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in Rust that defines one table and two reducers: one that inserts a row and one that updates a row.

TABLE
- user
- user (public)
- Struct: User
- Fields:
- id: u64 (primary key, auto_inc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in TypeScript that defines one table and two reducers: one that inserts a row and one that updates a row.

TABLE
- user
- user (public)
- Fields:
- id: number (u64, primary key, autoInc)
- name: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static partial class Module
{
[Table(Accessor = "User")]
[Table(Accessor = "User", Public = true)]
public partial struct User
{
[PrimaryKey, AutoInc] public ulong Id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use spacetimedb::{reducer, table, ReducerContext, Table};

#[table(accessor = user)]
#[table(accessor = user, public)]
pub struct User {
#[primary_key]
#[auto_inc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { table, schema, t } from 'spacetimedb/server';
const user = table(
{
name: 'user',
public: true,
},
{
id: t.u64().primaryKey().autoInc(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in C# that defines one table and two reducers: one that inserts a row and one that deletes a row.

TABLE
- User
- User (public)
- Struct: User
- Fields:
- Id: ulong (primary key, auto-increment)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in Rust that defines one table and two reducers: one that inserts a row and one that deletes a row.

TABLE
- user
- user (public)
- Struct: User
- Fields:
- id: u64 (primary key, auto_inc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in TypeScript that defines one table and two reducers: one that inserts a row and one that deletes a row.

TABLE
- user
- user (public)
- Fields:
- id: number (u64, primary key, autoInc)
- name: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public static partial class Module
{
[Table(Accessor = "User")]
[Table(Accessor = "User", Public = true)]
public partial struct User
{
[PrimaryKey, AutoInc] public ulong Id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use spacetimedb::{reducer, table, ReducerContext, Table};

#[table(accessor = user)]
#[table(accessor = user, public)]
pub struct User {
#[primary_key]
#[auto_inc]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { table, schema, t } from 'spacetimedb/server';
const user = table(
{
name: 'user',
public: true,
},
{
id: t.u64().primaryKey().autoInc(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in C# that defines one table and a reducer that performs insert, update, and delete in one call.

TABLE
- User
- User (public)
- Struct: User
- Fields:
- Id: ulong (primary key, auto-increment)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in Rust that defines one table and a reducer that performs insert, update, and delete in one call.

TABLE
- user
- user (public)
- Struct: User
- Fields:
- id: u64 (primary key, auto_inc)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Write a SpacetimeDB backend module in TypeScript that defines one table and a reducer that performs insert, update, and delete in one call.

TABLE
- user
- user (public)
- Fields:
- id: number (u64, primary key, autoInc)
- name: string
Expand Down
Loading
Loading