I was curious if this library is interoperable with existing Javascript code. let me elaborate.
We currently have a codebase written in Javascript, and we're looking to do a migration to Typescript. Today, we have dozens of Sequelize models written in JS. We'd like to do our migration gradually. Is that possible with this library? Could we have some models defined used sequelize-typescript and others defined using plain sequelize?
I'm encountering issues in preliminary experiments. Specifically, I'm having issues associating models that are defined using sequelize-typescript with models defined used sequelize. Ultimately, though, I'm looking for verification. I just want to make sure I'm not barking up the wrong tree.
If a gradual migration is possible, I was wondering if there is a migration guide or any documented best practices.
Thank you!
Hey @nadrane, currently there is no guide for that. I try to find out one. Is your model/sequelize setup like this: https://github.com/sequelize/express-example or different?
@RobinBuschmann So are you saying that it is possible to get sequelize and sequelize-typescript to play nicely together?
and yes, our setup is similar to the one you linked. We don't use sequelize['import'], but it's otherwise very similar. We use sequelize.define like they do
@nadrane In general yes. The thing is the initial loading of the models differs. For pure sequelize the models are already connected to the sequelize instance when defining them (sequelize.define('User', ...)), but they aren't with sequelize-typescript. For st they need to be added after the models are defined - with (sequelize.addModels([User]) or new Sequelize({modelPaths: ['./path/to/models/']})).
I'll try to find a best way to get them to work together (including associations). I've created a repo demonstrating it - It is not completed yet(!). But you can track my progress there, if you like to. As you can see, for now my pure sequelize model definitions aren't wrapped in a factory like in the sequelize/express-example. Are your models wrapped like so?
thank you so much! This is exactly what I needed. My models aren't quite wrapped like that, but I'll be able to infer what to do from here. You've covered all the major points for me 馃憤
I'm going to approach the problem using this repo and get back to you if I have questions. Thanks again!
Close this issue for now. @nadrane If you still have any questions, just reopen the issue.
Most helpful comment
@nadrane In general yes. The thing is the initial loading of the models differs. For pure sequelize the models are already connected to the sequelize instance when defining them (
sequelize.define('User', ...)), but they aren't with sequelize-typescript. For st they need to be added after the models are defined - with (sequelize.addModels([User])ornew Sequelize({modelPaths: ['./path/to/models/']})).I'll try to find a best way to get them to work together (including associations). I've created a repo demonstrating it - It is not completed yet(!). But you can track my progress there, if you like to. As you can see, for now my pure sequelize model definitions aren't wrapped in a factory like in the
sequelize/express-example. Are your models wrapped like so?