SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

`Identity` and `ConnectionId` should implement `IComparable`

Open rekhoff opened this issue 10 months ago • 1 comments

Issue:

When attempting to create a table that uses Identity as an index of a BTree like:

#[index(btree)]
pub identity: Identity,

Generated code in C# will throw the error: The type 'SpacetimeDB.Identity' must be convertible to 'System.IComparable<SpacetimeDB.Identity>' in order to use it as parameter 'Column' in the generic class 'SpacetimeDB.RemoteTableHandle<EventContext,Row>.BTreeIndexBase<Column>'

This is because SpacetimeDB.Identity does not implement the IComparable interface: https://github.com/clockworklabs/SpacetimeDB/blob/7cb509c2e2696a067e78734f07311a1d90e38fcf/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L204

While we are at it, it makes sense to implement IComparable for ConnectionId as well: https://github.com/clockworklabs/SpacetimeDB/blob/7cb509c2e2696a067e78734f07311a1d90e38fcf/crates/bindings-csharp/BSATN.Runtime/Builtins.cs#L121

rekhoff avatar Mar 05 '25 17:03 rekhoff

Note, unique constraints (which should be generating the same btree index) work just fine

#[unique]
pub identity: Identity,

joshua-spacetime avatar Mar 05 '25 18:03 joshua-spacetime

Resolved by PR https://github.com/clockworklabs/SpacetimeDB/pull/2354

rekhoff avatar Mar 07 '25 01:03 rekhoff