NielsCo / typespec-postgres

An expansion for TypeSpec enabling the definition of DB-Schema within the API-Definition in TypeSpec and emitting them to Postgres-Schema
Other
6 stars 0 forks source link

Allow to set names for the persisted referencing-property #11

Open NielsCo opened 1 year ago

NielsCo commented 1 year ago

Usually in the TypeSpec world we would name properties of other model-types like this:

@entity
model MyModel {
    anotherModel: AnotherModel;
}

@entity
model AnotherModel {
    @key id: numeric
}

this will produce the following schema:

CREATE TABLE AnotherModel (id NUMERIC PRIMARY KEY);

CREATE TABLE MyModel (
    anotherModel NUMERIC NOT NULL REFERENCES AnotherModel
);

Now in the db-domain the referencing colums are usually suffixed with "id" or "_id" or they have another name altogether. It would be a good feature to be able to name properties. This should not only be done for manual references but also for automatic references! (Maybe this needs another decorator altogether)