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

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

Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ internal IdUniqueIndex()
// Important: don't move this to the base class.
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public global::BTreeViews? Find(SpacetimeDB.Identity key) =>
DoFilter(key).Cast<global::BTreeViews?>().SingleOrDefault();
public global::BTreeViews? Find(SpacetimeDB.Identity key) => FindSingle(key);

public global::BTreeViews Update(global::BTreeViews row) => DoUpdate(row);
}
Expand Down Expand Up @@ -550,8 +549,7 @@ internal FooUniqueIndex()
// Important: don't move this to the base class.
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public global::MultiTableRow? Find(uint key) =>
DoFilter(key).Cast<global::MultiTableRow?>().SingleOrDefault();
public global::MultiTableRow? Find(uint key) => FindSingle(key);

public global::MultiTableRow Update(global::MultiTableRow row) => DoUpdate(row);
}
Expand Down Expand Up @@ -669,8 +667,7 @@ internal BarUniqueIndex()
// Important: don't move this to the base class.
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public global::MultiTableRow? Find(uint key) =>
DoFilter(key).Cast<global::MultiTableRow?>().SingleOrDefault();
public global::MultiTableRow? Find(uint key) => FindSingle(key);

public global::MultiTableRow Update(global::MultiTableRow row) => DoUpdate(row);
}
Expand Down Expand Up @@ -795,8 +792,7 @@ internal IdUniqueIndex()
// Important: don't move this to the base class.
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public global::PublicTable? Find(int key) =>
DoFilter(key).Cast<global::PublicTable?>().SingleOrDefault();
public global::PublicTable? Find(int key) => FindSingle(key);

public global::PublicTable Update(global::PublicTable row) => DoUpdate(row);
}
Expand Down Expand Up @@ -903,9 +899,7 @@ internal Unique1UniqueIndex()
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public global::RegressionMultipleUniqueIndexesHadSameName? Find(uint key) =>
DoFilter(key)
.Cast<global::RegressionMultipleUniqueIndexesHadSameName?>()
.SingleOrDefault();
FindSingle(key);

public global::RegressionMultipleUniqueIndexesHadSameName Update(
global::RegressionMultipleUniqueIndexesHadSameName row
Expand All @@ -929,9 +923,7 @@ internal Unique2UniqueIndex()
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public global::RegressionMultipleUniqueIndexesHadSameName? Find(uint key) =>
DoFilter(key)
.Cast<global::RegressionMultipleUniqueIndexesHadSameName?>()
.SingleOrDefault();
FindSingle(key);

public global::RegressionMultipleUniqueIndexesHadSameName Update(
global::RegressionMultipleUniqueIndexesHadSameName row
Expand Down Expand Up @@ -1033,8 +1025,7 @@ internal ScheduledIdUniqueIndex()
// Important: don't move this to the base class.
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public global::Timers.SendMessageTimer? Find(ulong key) =>
DoFilter(key).Cast<global::Timers.SendMessageTimer?>().SingleOrDefault();
public global::Timers.SendMessageTimer? Find(ulong key) => FindSingle(key);

public global::Timers.SendMessageTimer Update(global::Timers.SendMessageTimer row) =>
DoUpdate(row);
Expand Down
16 changes: 13 additions & 3 deletions crates/bindings-csharp/Codegen/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ record TableDeclaration : BaseTypeDeclaration<ColumnDeclaration>
public readonly EquatableArray<TableAccessor> TableAccessors;
public readonly EquatableArray<TableIndex> Indexes;

private readonly bool isRowStruct;

public int? GetColumnIndex(AttributeData attrContext, string name, DiagReporter diag)
{
var index = Members
Expand All @@ -428,6 +430,8 @@ public TableDeclaration(GeneratorAttributeSyntaxContext context, DiagReporter di
{
var typeSyntax = (TypeDeclarationSyntax)context.TargetNode;

isRowStruct = ((INamedTypeSymbol)context.TargetSymbol).IsValueType;

if (Kind is TypeKind.Sum)
{
diag.Report(ErrorDescriptor.TableTaggedEnum, typeSyntax);
Expand Down Expand Up @@ -481,6 +485,8 @@ public IEnumerable<string> GenerateTableAccessorFilters(TableAccessor tableAcces
var vis = SyntaxFacts.GetText(Visibility);
var globalName = $"global::{FullName}";

var uniqueIndexBase = isRowStruct ? "UniqueIndex" : "RefUniqueIndex";

foreach (var ct in GetConstraints(tableAccessor, ColumnAttrs.Unique))
{
var f = ct.Col;
Expand All @@ -492,12 +498,12 @@ public IEnumerable<string> GenerateTableAccessorFilters(TableAccessor tableAcces
}
var standardIndexName = ct.ToIndex().StandardIndexName(tableAccessor);
yield return $$"""
{{vis}} sealed class {{f.Name}}UniqueIndex : UniqueIndex<{{tableAccessor.Name}}, {{globalName}}, {{f.Type.Name}}, {{f.Type.BSATNName}}> {
{{vis}} sealed class {{f.Name}}UniqueIndex : {{uniqueIndexBase}}<{{tableAccessor.Name}}, {{globalName}}, {{f.Type.Name}}, {{f.Type.BSATNName}}> {
internal {{f.Name}}UniqueIndex() : base("{{standardIndexName}}") {}
// Important: don't move this to the base class.
// C# generics don't play well with nullable types and can't accept both struct-type-based and class-type-based
// `globalName` in one generic definition, leading to buggy `Row?` expansion for either one or another.
public {{globalName}}? Find({{f.Type.Name}} key) => DoFilter(key).Cast<{{globalName}}?>().SingleOrDefault();
public {{globalName}}? Find({{f.Type.Name}} key) => FindSingle(key);
public {{globalName}} Update({{globalName}} row) => DoUpdate(row);
}
{{vis}} {{f.Name}}UniqueIndex {{f.Name}} => new();
Expand Down Expand Up @@ -570,6 +576,10 @@ private IEnumerable<string> GenerateReadOnlyAccessorFilters(TableAccessor tableA
var vis = SyntaxFacts.GetText(Visibility);
var globalName = $"global::{FullName}";

var uniqueIndexBase = isRowStruct
? "global::SpacetimeDB.Internal.ReadOnlyUniqueIndex"
: "global::SpacetimeDB.Internal.ReadOnlyRefUniqueIndex";

foreach (var ct in GetConstraints(tableAccessor, ColumnAttrs.Unique))
{
var f = ct.Col;
Expand All @@ -582,7 +592,7 @@ private IEnumerable<string> GenerateReadOnlyAccessorFilters(TableAccessor tableA

yield return $$$"""
public sealed class {{{f.Name}}}Index
: global::SpacetimeDB.Internal.ReadOnlyUniqueIndex<
: {{{uniqueIndexBase}}}<
global::SpacetimeDB.Internal.ViewHandles.{{{tableAccessor.Name}}}ReadOnly,
{{{globalName}}},
{{{f.Type.Name}}},
Expand Down
24 changes: 24 additions & 0 deletions crates/bindings-csharp/Runtime/Internal/FFI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ internal static partial class FFI
#endif
;

const string StdbNamespace10_4 =
#if EXPERIMENTAL_WASM_AOT
"spacetime_10.4"
#else
"bindings"
#endif
;

[NativeMarshalling(typeof(Marshaller))]
public struct CheckedStatus
{
Expand Down Expand Up @@ -195,6 +203,22 @@ public static partial CheckedStatus datastore_table_scan_bsatn(
out RowIter out_
);

[LibraryImport(StdbNamespace10_4)]
public static partial CheckedStatus datastore_index_scan_point_bsatn(
IndexId index_id,
ReadOnlySpan<byte> point,
uint point_len,
out RowIter out_
);

[LibraryImport(StdbNamespace10_4)]
public static partial CheckedStatus datastore_delete_by_index_scan_point_bsatn(
IndexId index_id,
ReadOnlySpan<byte> point,
uint point_len,
out uint out_
);

[LibraryImport(StdbNamespace10_0)]
public static partial CheckedStatus datastore_index_scan_range_bsatn(
IndexId index_id,
Expand Down
Loading
Loading