Implement column aliases in C# and Rust modules
We'd like to be able to do something like this:
// We're using this table as a singleton, so in this table
// there only be one element where the `id` is 0.
[Table(Name = "config", Public = true)]
public partial struct Config
{
[PrimaryKey]
[Column(Name = "id")]
public uint Id;
[Column(Name = "world_size")]
public ulong WorldSize;
}
// We're using this table as a singleton, so in this table
// there only be one element where the `id` is 0.
#[spacetimedb::table(name = config, public)]
pub struct Config {
#[primary_key]
pub id: u32,
#[column(name = "foobar")]
pub foobar: u64,
}
Exactly spelling not proposed. Needs design work. This is a common feature in ORMs:
https://orm.drizzle.team/docs/sql-schema-declaration#tables-and-columns-declaration
FWIW we already use the standard [DataMember(Name = "...")] attribute in autogenerated C# code to preserve column names for JSON representation (which was important for BitCraft):
https://github.com/clockworklabs/SpacetimeDB/blob/729dbb149599b4535c3b4d4e2fb4594be7ea448f/crates/cli/tests/snapshots/codegen__codegen_csharp.snap#L110-L119
In C# it might make sense to reuse the same attribute for server-side as well, instead of introducing a separate one, since DataMember can be reused by various serializers.
The motivation for this ticket is that it's not now currently possible to follow SQL table/column name style suggestions and also not get warning in C# about not using snake_case names for variables.
(NICHE) It also makes it impossible to migrate a Rust project to C# and vice versa without changing column names which is not currently possible.