sequelize-auto icon indicating copy to clipboard operation
sequelize-auto copied to clipboard

Using Typescript output with multiple schemas

Open twastvedt opened this issue 3 years ago • 2 comments

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?

twastvedt avatar Sep 21 '21 18:09 twastvedt

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.

steveschmitt avatar Sep 21 '21 18:09 steveschmitt

That makes sense to me. That would be great!

twastvedt avatar Sep 22 '21 08:09 twastvedt