mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-14 03:37:55 -04:00
4143c15b08
# 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>
31 lines
745 B
C#
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 { }
|