admin管理员组文章数量:1221302
I'm trying to use sequelize with typescript, but don't know how. I installed a package named sequelize-cli-typescript, but it does not work with sequelize v6. And I know it is better to use migrations to perform my database. How can I do that?
I'm trying to use sequelize with typescript, but don't know how. I installed a package named sequelize-cli-typescript, but it does not work with sequelize v6. And I know it is better to use migrations to perform my database. How can I do that?
Share Improve this question asked Jan 17, 2021 at 20:08 Hadi AhmadiHadi Ahmadi 5791 gold badge3 silver badges10 bronze badges 4- sequelize.org/master/manual/typescript.html? – evolutionxbox Commented Jan 17, 2021 at 22:44
- 1 Wanna use migrations, not sync – Hadi Ahmadi Commented Jan 18, 2021 at 2:17
- This question leaves us to ask so many other questions we don't know where to start to help. – evolutionxbox Commented Jan 18, 2021 at 10:47
- OK I just want to create my migrations with sequelize-cli, and output a ts file instead of js file. That's it, I don't wanna add models manually and then sync them. I just want to add models using migrations. sequelize-cli package is for js, not for ts. It generates js file,not ts. – Hadi Ahmadi Commented Jan 18, 2021 at 11:30
2 Answers
Reset to default 8You pretty much need to transpile your code into javascript if you're going to use migrations, because sequelize-cli doesn't know anything about typescript. We compile our stuff to ./dist
right before running npx sequelize-cli db:migrate
via npx tsc -p .
with a tsconfig.json
file that has these lines:
{
"compilerOptions": {
"target": "es6",
// ...
"outDir": "dist",
// ...
}
}
The .sequelizerc
file (which is used by sequelize-cli only) will also point to dist, e.g.:
const path = require('path');
module.exports = {
'config': path.resolve('./dist/src/config', 'config.js'),
'models-path': path.resolve('./dist/src/db', 'models'),
'seeders-path': path.resolve('./dist/src/db', 'seeders'),
'migrations-path': path.resolve('./dist/src/db', 'migrations')
}
Use umzug. It powers sequelize cli.
本文标签: javascriptUsing sequelize cli with typescriptStack Overflow
版权声明:本文标题:javascript - Using sequelize cli with typescript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739364667a2159979.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论