sequelize / sequelize-auto

Automatically generate bare sequelize models from your database.
2.91k stars 529 forks source link

Using Typescript output with multiple schemas #559

Open twastvedt opened 3 years ago

twastvedt commented 3 years ago

I have a project with a MySql server which contains multiple databases with the same schema. Typescript classes created by Sequelize-auto are working with one of the databases, but I am unable to use the generated classes with more than one database at the same time because Sequelize uses static properties on the class to hold the Sequelize instance.

It looks like I need to use Sequelize.define instead (see "Usage of sequelize.define" section: https://sequelize.org/master/manual/typescript.html), to create independent model objects which are tied to different Sequelize instances. So, the es5 output from sequelize-auto would be great, but it doesn't come with Typescript definitions, which I'd really like to have. I believe that this scenario would require a non-trivial addition of Typescript output using Sequelize.define but maybe (hopefully) I'm mistaken?

steveschmitt commented 3 years ago

Hmm. Maybe we could separate the model property structure, so then you could call either init or define on it, depending upon your use case.

twastvedt commented 3 years ago

That makes sense to me. That would be great!