rmp135 / sql-ts

Generate TypeScript interfaces from a SQL database.
MIT License
477 stars 65 forks source link

Automatically import relationships from database #110

Closed Saint-Riversmith closed 2 years ago

Saint-Riversmith commented 2 years ago

Greetings,

I have yet to find a way to automatically map relationship between entities while syncing from a database. Consider the two following entities as examples:

export interface TicketEntity {
  'ID: number;
  'Name': string;
  'Client': number;
}

export interface ClientEntity {
  'ID'?: number;
  'Name': string;
}

In this case, the "Client" property of the TicketEntity interface refers to an instance of ClientEntity, and it is marked as such in the DB by foreign key. Is there a way to change it so that the "Client" property is of type "ClientEntity" instead of the current "number", without overiding every relationship property in all of my models one by one?

The database is PostgreSQL, in case this affects anything.

rmp135 commented 2 years ago

This isn't something that this library is intended for, it's just for one-to-one mappings of database fields, nothing more fancy than that.

Overriding the type of the column wouldn't do much good as the data from the foreign table hasn't been fetched, it would remain as the number.