kristiandupont / kanel

Generate Typescript types from Postgres
https://kristiandupont.github.io/kanel/
MIT License
829 stars 57 forks source link

Missing support for INHERITS #533

Open ian-weir opened 4 months ago

ian-weir commented 4 months ago

When using the INHERITS functionality in a database the generated types to not reflect this inheritence. Using the example from the Postgresql documentation:

CREATE TABLE cities (
    name            text,
    population      float,
    elevation       int     -- in feet
);

CREATE TABLE capitals (
    state           char(2)
) INHERITS (cities);

Kanel would output something like:

//Cities.ts
export default interface Cities {
  name: string;
  population: number;
  elevation: number;
}

//Capitals.ts
export default interface Capitals {
  state: string;
}

Which doesn't correctly represent the model of the database. The correct output would look like:

//Capitals.ts
export default interface Capitals extends Cities {
  state: string;
}

I really like the rest of the way Kanel behaves but this is sadly a blocker from me using it at work :(

kristiandupont commented 4 months ago

Ah yes, I can see that this is a missing feature. I will need to add support for inheritance to extract-pg-schema for this to be possible.