SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Create `RangedIndex` interface used in C# codegen similar to Rust

Open kazimuth opened this issue 10 months ago • 2 comments

Currently, the module-side generated data structures for indexes don't implement a single interface, despite all having the same interface. The generated code for these looks like

public sealed class nameIndex() : SpacetimeDB.Internal.IndexBase<global::SpacetimeDB.Modules.ModuleTestCs.TestE>("test_e_name_idx_btree") {
    public IEnumerable<global::SpacetimeDB.Modules.ModuleTestCs.TestE> Filter(string name) =>
        DoFilter(new SpacetimeDB.Internal.BTreeIndexBounds<string, SpacetimeDB.BSATN.String>(name));

    public ulong Delete(string name) =>
        DoDelete(new SpacetimeDB.Internal.BTreeIndexBounds<string, SpacetimeDB.BSATN.String>(name));

    public IEnumerable<global::SpacetimeDB.Modules.ModuleTestCs.TestE> Filter(Bound<string> name) =>
        DoFilter(new SpacetimeDB.Internal.BTreeIndexBounds<string, SpacetimeDB.BSATN.String>(name));

    public ulong Delete(Bound<string> name) =>
        DoDelete(new SpacetimeDB.Internal.BTreeIndexBounds<string, SpacetimeDB.BSATN.String>(name));

}

Either IndexBase should grow more methods, an interface should be added, or this sort of index should be converted to a single data structure. This is a wart that could be fixed backwards-compatibly since it is only visible inside modules.

kazimuth avatar Feb 26 '25 21:02 kazimuth

Dev ex team to triage based on user requests. Core team may implement.

gefjon avatar Mar 12 '25 20:03 gefjon

This may not be possible, there are comments scattered around saying C# generics can interact badly with mixed use of struct and reference types. Will need careful testing.

kazimuth avatar Mar 25 '25 16:03 kazimuth