Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jeremie/cs module #1719

Merged
merged 27 commits into from
Sep 27, 2024
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
8 changes: 8 additions & 0 deletions crates/bindings-csharp/BSATN.Runtime/Db.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SpacetimeDB;

public abstract record DbContext<DbView>(DbView Db)
where DbView : class, new()
{
public DbContext()
: this(new DbView()) { }
}
35 changes: 19 additions & 16 deletions crates/bindings-csharp/Codegen.Tests/fixtures/server/Lib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public partial struct CustomStruct
}

[SpacetimeDB.Type]
public partial struct CustomClass
public partial class CustomClass
RReverser marked this conversation as resolved.
Show resolved Hide resolved
{
public const int IGNORE_ME = 0;
public static readonly string IGNORE_ME_TOO = "";
public int IntField;
public string StringField;
public int IntField = 0;
public string StringField = "";
}

[StructLayout(LayoutKind.Auto)]
public partial struct CustomClass
public partial class CustomClass
{
public int IgnoreExtraFields;
}
Expand All @@ -44,7 +44,8 @@ public partial class PrivateTable { }
[SpacetimeDB.Table]
public partial struct PublicTable
{
[SpacetimeDB.Column(ColumnAttrs.PrimaryKeyAuto)]
[SpacetimeDB.AutoInc]
[SpacetimeDB.PrimaryKey]
public int Id;

public byte ByteField;
Expand Down Expand Up @@ -81,18 +82,18 @@ public partial struct PublicTable
public static partial class Reducers
{
[SpacetimeDB.Reducer]
public static void InsertData(PublicTable data)
public static void InsertData(ReducerContext ctx, PublicTable data)
{
data.Insert();
ctx.Db.PublicTable.Insert(data);
Log.Info("New list");
foreach (var item in PublicTable.Iter())
foreach (var item in ctx.Db.PublicTable.Iter())
{
Log.Info($"Item: {item.StringField}");
}
}

[SpacetimeDB.Reducer]
public static void ScheduleImmediate(PublicTable data)
public static void ScheduleImmediate(ReducerContext ctx, PublicTable data)
{
VolatileNonatomicScheduleImmediateInsertData(data);
}
Expand All @@ -107,7 +108,7 @@ public static partial class AndClasses
[SpacetimeDB.Reducer("test_custom_name_and_reducer_ctx")]
public static void InsertData2(ReducerContext ctx, PublicTable data)
{
data.Insert();
ctx.Db.PublicTable.Insert(data);
}
}
}
Expand All @@ -122,7 +123,7 @@ public partial struct SendMessageTimer
}

[SpacetimeDB.Reducer]
public static void SendScheduledMessage(SendMessageTimer arg)
public static void SendScheduledMessage(ReducerContext ctx, SendMessageTimer arg)
{
// verify that fields were auto-added
ulong id = arg.ScheduledId;
Expand All @@ -133,10 +134,12 @@ public static void SendScheduledMessage(SendMessageTimer arg)
[SpacetimeDB.Reducer(ReducerKind.Init)]
public static void Init(ReducerContext ctx)
{
new SendMessageTimer
{
Text = "bot sending a message",
ScheduledAt = ctx.Time.AddSeconds(10),
}.Insert();
ctx.Db.SendMessageTimer.Insert(
new SendMessageTimer
{
Text = "bot sending a message",
ScheduledAt = ctx.Time.AddSeconds(10),
}
);
}
}
Loading
Loading