Hi Dev community 👋🏾!
I just decided that I want to write a post so here I AM. I didn't know what to write about and I landed on the idea of Sequel...
For further actions, you may consider blocking this person and/or reporting abuse
Sequelize-typescript package is very helpful, it allows to define model with decorators and transpiles into easily usable objects to pass through graphql, without creating additional boilerplate DTO.
Also, check out Nestjs. It's very flexible, code first, easy to use and
"federationable" typescript based, backend framework.
nestjs.com
Totally agree with you! That's why I added the note at the end.
I'm changing a lot of stuff both in the backend and the frontend. It's something kinda like an extreme makeover for the project. 😅
How would the sequelize-cli db:migrate command work with typescript?
Just dropping by the comments to say that you saved me! Was having the same problem related to the Sequelize subclass and didn't find anything useful in Google until I came across your post.
Really appreciated!
Maybe a bit silly, but I was starting without
sequelize
installed, and needed to runnpm i sequelize
beforenpx sequelize-cli init
Your model files are ending with .ts but
db/models/index.js
is looking for .js files so this probably doesn't work.I think it will be better to keep the db Object that is being generated based on the files inside the models so you can avoid :
Book.belongsTo called with something that's not a subclass of Sequelize.Model error
Nice heads up, i love it
Thank you! This improves DX quite significantly
Awesome post, thank you.
But I wondering how to add or remove column to existed model.
Hey @minhdc998, you should be able to remove the property from your model and then use the sequelize-cli to generate a migration in which you would write a table alter statement to remove it from the database.
There is supposed to be an
alter
property you can pass to the sync method which might attempt to do this for you, but I've had issues with it creating duplicate foreign key constraints, so I haven't used it much.Thanks a lot.
Hi,
Awesome article I am actually using it the exact way. Do you have any repo that using this approach? Also how is it possible to create with associations? Typescript seems to not like it.
Thanks