Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to generate a typescript file in sequelize-cli-typescript?


Asked by Priscilla Lozano on Dec 13, 2021 TypeScript



With sequelize-cli-typescript, model:generate produces TypeScript files in the same two folders (or again, as specified in your.sequelizerc file). But before you can run db:migrate you must compile your migrations. (The step of compiling your migrations is left to you.)
Indeed,
It's usually the case that the compiled JavaScript code will be put in a different directory than the source TypeScript code, so whereas sequelize-cli had one migrations-path setting, sequelize-cli-typescript has two: migrations-source-path and migrations-compiled-path, which default to /migrations and /migrations/compiled respectively.
In addition, With sequelize-cli, the model:generate command would produce JavaScript files in two folders: /models and /migrations, or other folders as specified in your .sequelizerc file. The db:migrate command would then exe ute these JavaScript files to update your database.
Also,
Using Sequelize CLI to run the migration file written in Typescript. After we wrote the migrations in Typescript, we were required to use the Sequelize CLI to run them. However, Sequelize CLI expects migrations to be written in Javascript.
Moreover,
The sequelize instance has a reference to the database connection so when we create our models we use this instance so we can communicate with the database through the models. The first file is done and a bunch more to go.