mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-20 22:52:07 -04:00
52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
namespace SpacetimeDB.Examples.QuickStart.Server;
|
|
|
|
using SpacetimeDB;
|
|
|
|
[Table(Name = "person", Public = true)]
|
|
public partial struct Person
|
|
{
|
|
[AutoInc]
|
|
[PrimaryKey]
|
|
public uint id;
|
|
public string name;
|
|
|
|
[Index.BTree]
|
|
public byte age;
|
|
}
|
|
|
|
static partial class Module
|
|
{
|
|
[SpacetimeDB.Reducer]
|
|
public static void add(ReducerContext ctx, string name, byte age)
|
|
{
|
|
ctx.Db.person.Insert(new Person { name = name, age = age });
|
|
}
|
|
|
|
[SpacetimeDB.Reducer]
|
|
public static void say_hello(ReducerContext ctx)
|
|
{
|
|
foreach (var person in ctx.Db.person.Iter())
|
|
{
|
|
Log.Info($"Hello, {person.name}!");
|
|
}
|
|
Log.Info("Hello, World!");
|
|
}
|
|
|
|
[SpacetimeDB.Reducer]
|
|
public static void list_over_age(ReducerContext ctx, byte age)
|
|
{
|
|
foreach (var person in ctx.Db.person.age.Filter((age, byte.MaxValue)))
|
|
{
|
|
Log.Info($"{person.name} has age {person.age} >= {age}");
|
|
}
|
|
}
|
|
|
|
[SpacetimeDB.Reducer]
|
|
public static void log_module_identity(ReducerContext ctx)
|
|
{
|
|
// Note: we use ToLower() because Rust side stringifies identities as lowercase hex.
|
|
// Is this something we need to align on in the future?
|
|
Log.Info($"Module identity: {ctx.Identity.ToString().ToLower()}");
|
|
}
|
|
}
|