Files
rekhoff 4143c15b08 C# bindings for views (#3585)
# Description of Changes

Updates C# bindings to allow module authors to define `View`s and
`AnonymousView`s using the pattern:
```
[SpacetimeDB.View]
public static ExampleData? GetExampleDataById(ViewContext ctx, uint id)
{
    return ctx.Db.ExampleData.Id.Find(id);
}
	
[SpacetimeDB.View]
public static ExampleData? GetAnonymousExampleDataById(AnonymousViewContext ctx, uint id)
{
    return ctx.Db.ExampleData.Id.Find(id);
}
```
During publishing of a C# module, the views data will be converted into
`RawViewDefV9`

# API and ABI breaking changes

No known breaking changes

# Expected complexity level and risk

2

# Testing

- [X] Locally tested locally adding the above sample pattern to the
`sdks\csharp\examples~\regression-tests\server` test and performing a
`dotnet build` and a `spacetime publish test`, both of which succeeded.

---------

Signed-off-by: Jason Larabie <jason@clockworklabs.io>
Co-authored-by: Jason Larabie <jason@clockworklabs.io>
2025-11-11 12:01:44 -05:00

31 lines
745 B
C#

namespace SpacetimeDB.Internal;
using SpacetimeDB.BSATN;
public interface IView
{
RawViewDefV9 MakeViewDef(ITypeRegistrar registrar);
// This one is not static because we need to be able to store IView in a list.
byte[] Invoke(BinaryReader reader, IViewContext args);
}
public interface IAnonymousView
{
RawViewDefV9 MakeAnonymousViewDef(ITypeRegistrar registrar);
// This one is not static because we need to be able to store IAnonymousView in a list.
byte[] Invoke(BinaryReader reader, IAnonymousViewContext args);
}
public interface IViewContext
{
public static Identity GetIdentity()
{
FFI.identity(out var identity);
return identity;
}
}
public interface IAnonymousViewContext { }