Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement column alias's in C# and Rust modules #2168

Open
cloutiertyler opened this issue Jan 24, 2025 · 1 comment
Open

Implement column alias's in C# and Rust modules #2168

cloutiertyler opened this issue Jan 24, 2025 · 1 comment

Comments

@cloutiertyler
Copy link
Contributor

cloutiertyler commented Jan 24, 2025

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

@cloutiertyler cloutiertyler changed the title Implement column alias's in C# and Rust Implement column alias's in C# and Rust modules Jan 24, 2025
@RReverser
Copy link
Contributor

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):

[SpacetimeDB.Type]
[DataContract]
public partial class Player : IDatabaseRow
{
[DataMember(Name = "identity")]
public SpacetimeDB.Identity Identity;
[DataMember(Name = "player_id")]
public ulong PlayerId;
[DataMember(Name = "name")]
public string Name;

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants