Using Sequelize With TypeScript: Basic Project Setup
HTML-код
- Опубликовано: 9 окт 2024
- #Sequelize #TypeScript
In this video, we set up a project using Sequelize and TypeScript along with a Postgres database.
Final code: github.com/wil...
Sequelize Docs: sequelize.org/...
TypeScript Docs: www.typescript...
This is probably the only tutorial I have seen that also covers how where in the documentation things are. Thank you so much!
Glad it helped.
Cheers!
almost 2 years later and your video saved me! thank you, sequelize was making me lose it bit time. I followed the docs 100% and yet wasn't able to make it work, but following your instructions (even though some thing changed, and I implemented some changes because of it) I made it work, thank you so much
Man can I just say, this is probably the best video on this topic out there.
Your way of explaining, coupled with the general structure of the video (referencing the doc, mentioning how other people do stuff, and even just learning by doing) is my favourite so far.
Thank you
This video solved all my Sequelize with TypeScript problems
Really awesome quick hands on tutorial. Spent whole afternoon with it, it turns on many useful part here. So thanks again!
Thanks a lot!
This video was really helpful and enlightening 🖤
I loved how you showed us important parts of the documentation while coding.
Keep it up 👏
just this tutorial showed me what i need to know about sequelize
Great tutorial! I personally like to write my own models without sequelize-cli and also write my own migrations and run them with umzug library, which is quite popular. TypeScript part cleared some things up for me so thanks for that!
Thank you so much! Helped clear up a lot of frustrations. Would be great if the sequelize documentation for Typescript wasn't just a code dump.
Excellent tutorial. Thanks for putting this up. Only wish is before ending you would have added a where clause in the query, but super complete!
Thanks! Yeah, I thought about going deeper with the queries, but the video was getting pretty long.
@@willjw3717 No rule against making another amazing video... just saying ;-)
@@CptBongue The funny thing is that I had already decided to go with Prisma 2 as my go-to ORM when I made this video. If I do go back to Sequelize, I will definitely put up another video or two.
Cheers!
you gave a very good explanation of this topic
I was making a project and get stuck on the model type giving me errors. I skipped to that section and you saved me! Thank you
Thanks! This is what have been looking for.
I have been looking for this video, thank you so much.
Thanks for the tutorial.
... A little advise, try to lower the volume of the keystrokes, they are louder than your voice, it is not pleaseant when wering headsets.
you're voice is legendary boss!
Really Great , Thank you ! Only one issue which I am facing is getting error as ---- Cannot find "C:\Projects\****\******\config\config.json". Have you run "sequelize init"? ---- While running the command node_modules/.bin/sequelize db:migrate
Sorry to hear that. Hope you get it working quickly!
Thanks for watching.
can u solve?
@@nahueljj just check the path for import statement for config is correct. Error should be fixed after that
Thanks for the video. can you explain an API in the next videos?
how did you structure your folder? where do business logic and controllers and such come from?
Hopefully, I'll be able to do another video or two and make this a series. Thanks for watching!
Thanks a lot for this video! It helped me a lot to set all this up!
It works but when I make the tsc command, node fails trying to excecute yield models_1.default.Building.findAll 😓
Great Tutorial. Please do the series
Excellent tutorial, got like and one more subscriber. Hugs from Brazil!!
Hey mate, thanks for the really well put video! Watched a few videos, but yours is definitely the best so far! :)
Do you intend to do a Sequelize migrations setup video?
Keep up the great work!
Thanks, and sorry for the slow response.
I don't have any plans to at this time. I would say check out Ben Awad. He seems to have done a fair number of videos on Sequelize and other ORMs.
const result = await db.User.findAll({
include: {
model: db.Project
}
})
If I fetch the data using db.User then the result type is any insted of UserAttributes! How can I achieve the correct type for each model?
Thank you so much for this video ! total genius !!!!!
Awsome bro!, thank you so much. if you could explain api in next videos it would be great
Hi thank you for the nice training video. can you please share what theme icons are you using in vs code?
also vs code settings
vscode-icons
so every project that uses seq has to enable the 'allowJS' flag for those seq-cli generated js files?
Great tutorial, thanks a lot!
I have three tables. One associated with the other two. I want to return few attributes from all the tables using joins. How can I do that? Please suggest.
Great tutorial, thanks for your work mate
Awesome tutorial, I really could not figure all of this out from the documentation. But one thing I am still struggling is with the migrations, because to run the migrations the sequelize-cli needs to be able to interpret the file and it apparently can't when we use typescipt, is there any workarounds for that?
Hi Lucas!
What i've done to solve this issue was:
1) // .sequelizerc
const path = require('path');
module.exports = {
config: path.resolve(__dirname, 'dist', 'config', 'database.js'),
'migrations-path': path.resolve(__dirname, 'dist', 'application', 'database', 'migrations'),
'seeders-path': path.resolve(__dirname, 'dist', 'application', 'database', 'seeders'),
'models-path': path.resolve(__dirname, 'dist', 'application', 'database', 'models')
}
-------------------------------------------------------------------------------------------------------------------------------------------
2 ) // src/application/database/migrations
generate all migrations through sequelize-cli and add .ts extension to them. example:
$ sequelize-cli migration:generate --name customers // output 20220120124320-customers.js
Copy and paste the file and change its extension from .js to .ts in your migration folder.
> src/application/database/migrations/20220120124320-customers.ts
// write your code into it...
-------------------------------------------------------------------------------------------------------------------------------------------
3 ) !FINAL STEP!
the main point here is when you run "yarn build" or "npm run build" or whatever, it'll generate a folder called "dist", which contains all your files in .JS extension, and now your sequelize can interpret your files, 'cause your .sequelizerc file is configurated to read your migrations from dist folder.
Really awesome, but the migrations files are js, if using sequelize-cli to run migrations how?
Thanks. I haven't gone down that road yet, but if you come up with something and make a blog post or a video about it, feel free to link to it here.
I notice you are using CommonJS, will this work with ES Modules?
Thanks so much!
Keep up the good work!
Thank you!
what about the package sequelize-typescript?
46:05 Wait, that shouldn't be a an async/await function ? Is not insert something into a DB an asynchronous procedure ?
That won't be necessary here ig, unless u want to log or do something after each use gets submitted
How is project can be run build ?
what is the benefit of typescript, if the defined model is used by a db which has any type?
Exactly !!!!
i followed this whole thing just to not be able to use any of the models i created when trying to access them via the 'db' import of the index file. what a waste
thanks great job!
how to create migration sequelize in typescript.
Сегодня всё гораздо лучше с типизацией Sequelize
Thanks alot for the content #Will :)
You have not covered migration topics.
this video is deprecates since the release of sequelize-typescript
Why am I reading this after finishing the f**** tutorial? xD
No. sequelize-typescript is not affiliated with Sequelize. That said there is more updated documentation for typescript support on sequelize's website.
26:51 There has to be a better way than having to add these attributes 3 times
Copying and pasting would have sped the process up for sure.
Btw, using `sequelize.sync()` is not advised. Sequelize encourage the use of the CLI to run migration or seeders
Yeah, I mentioned in the video that migrations are recommended if developing an app for production. It's fine to use sequelize.sync() for exploration when you know you're going to add and drop tables several times.
when build app /config/config.js not work..GG
Thanks
COYG
that's the best
29:00 Asociations