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...

Комментарии • 75

  • @greykor140
    @greykor140 3 года назад +32

    This is probably the only tutorial I have seen that also covers how where in the documentation things are. Thank you so much!

    • @willjw3717
      @willjw3717  3 года назад +1

      Glad it helped.
      Cheers!

  • @raulriatosilva1734
    @raulriatosilva1734 Год назад +2

    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

  • @rewrose2838
    @rewrose2838 Год назад

    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

  • @THANANANWORRAWONGVUTIKRAI
    @THANANANWORRAWONGVUTIKRAI 5 месяцев назад +2

    This video solved all my Sequelize with TypeScript problems

  • @GfastGao
    @GfastGao 3 года назад +2

    Really awesome quick hands on tutorial. Spent whole afternoon with it, it turns on many useful part here. So thanks again!

  • @faris.abuali
    @faris.abuali 2 года назад +3

    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 👏

  • @icokafor2878
    @icokafor2878 9 месяцев назад

    just this tutorial showed me what i need to know about sequelize

  • @didziszvaigzne7679
    @didziszvaigzne7679 2 года назад +1

    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!

  • @deanhuber7849
    @deanhuber7849 2 года назад

    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.

  • @CptBongue
    @CptBongue 3 года назад +1

    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!

    • @willjw3717
      @willjw3717  3 года назад

      Thanks! Yeah, I thought about going deeper with the queries, but the video was getting pretty long.

    • @CptBongue
      @CptBongue 3 года назад

      @@willjw3717 No rule against making another amazing video... just saying ;-)

    • @willjw3717
      @willjw3717  3 года назад +1

      @@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!

  • @abbaemmanuel5736
    @abbaemmanuel5736 4 месяца назад

    you gave a very good explanation of this topic

  • @JonnyLove
    @JonnyLove 5 месяцев назад

    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

  • @lawrencekatuva8735
    @lawrencekatuva8735 3 года назад +2

    Thanks! This is what have been looking for.

  • @sigmacoolbeatz7237
    @sigmacoolbeatz7237 3 года назад +2

    I have been looking for this video, thank you so much.

  • @martinmendez695
    @martinmendez695 Год назад

    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.

  • @shivShaktitech
    @shivShaktitech 9 месяцев назад

    you're voice is legendary boss!

  • @happinessprogram
    @happinessprogram 3 года назад +2

    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

    • @willjw3717
      @willjw3717  3 года назад

      Sorry to hear that. Hope you get it working quickly!
      Thanks for watching.

    • @nahueljj
      @nahueljj 2 года назад

      can u solve?

    • @dvalley56
      @dvalley56 2 года назад

      @@nahueljj just check the path for import statement for config is correct. Error should be fixed after that

  • @ratidevdariani2764
    @ratidevdariani2764 3 года назад +1

    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?

    • @willjw3717
      @willjw3717  3 года назад +2

      Hopefully, I'll be able to do another video or two and make this a series. Thanks for watching!

  • @Robytsu
    @Robytsu 2 года назад

    Thanks a lot for this video! It helped me a lot to set all this up!

  • @jorgegarnicablanco8136
    @jorgegarnicablanco8136 2 года назад

    It works but when I make the tsc command, node fails trying to excecute yield models_1.default.Building.findAll 😓

  • @rakeshk1932
    @rakeshk1932 3 года назад

    Great Tutorial. Please do the series

  • @antonioteixeira1779
    @antonioteixeira1779 2 года назад

    Excellent tutorial, got like and one more subscriber. Hugs from Brazil!!

  • @roobyx
    @roobyx 2 года назад

    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!

    • @willjw3717
      @willjw3717  2 года назад

      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.

  • @SanjayS-fz1lw
    @SanjayS-fz1lw 7 месяцев назад

    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?

  • @sergioarieljuarez90
    @sergioarieljuarez90 2 года назад

    Thank you so much for this video ! total genius !!!!!

  • @jose-sanchez-mza
    @jose-sanchez-mza 3 года назад

    Awsome bro!, thank you so much. if you could explain api in next videos it would be great

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer 2 года назад +1

    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

  • @guygolan3685
    @guygolan3685 2 года назад

    so every project that uses seq has to enable the 'allowJS' flag for those seq-cli generated js files?

  • @juanfrancoledesma585
    @juanfrancoledesma585 Год назад

    Great tutorial, thanks a lot!

  • @honestindian2496
    @honestindian2496 3 года назад

    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.

  • @samfreshly5331
    @samfreshly5331 3 года назад

    Great tutorial, thanks for your work mate

  • @lucassilvaennes5302
    @lucassilvaennes5302 2 года назад

    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?

    • @gugahenrique6799
      @gugahenrique6799 2 года назад +1

      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.

  • @bhargavas678
    @bhargavas678 3 года назад +1

    Really awesome, but the migrations files are js, if using sequelize-cli to run migrations how?

    • @willjw3717
      @willjw3717  3 года назад

      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.

  • @madcolor
    @madcolor 2 года назад

    I notice you are using CommonJS, will this work with ES Modules?

  • @applicationary
    @applicationary Год назад

    Thanks so much!

  • @Harduex
    @Harduex 3 года назад

    Keep up the good work!

  • @MikhailAdutskevich
    @MikhailAdutskevich Год назад

    Thank you!

  • @sarodoumanian7468
    @sarodoumanian7468 2 года назад

    what about the package sequelize-typescript?

  • @axelelpro
    @axelelpro 2 года назад

    46:05 Wait, that shouldn't be a an async/await function ? Is not insert something into a DB an asynchronous procedure ?

    • @dvalley56
      @dvalley56 2 года назад

      That won't be necessary here ig, unless u want to log or do something after each use gets submitted

  • @PhearunUM
    @PhearunUM Год назад

    How is project can be run build ?

  • @allone258
    @allone258 Год назад

    what is the benefit of typescript, if the defined model is used by a db which has any type?

  • @0tiii
    @0tiii Год назад

    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

  • @SachinWakpaijan
    @SachinWakpaijan 3 года назад

    thanks great job!

  • @Mahmudulhasan-ts5hm
    @Mahmudulhasan-ts5hm 2 года назад

    how to create migration sequelize in typescript.

  • @pinkierar_real
    @pinkierar_real 2 года назад

    Сегодня всё гораздо лучше с типизацией Sequelize

  • @realkevinbrian
    @realkevinbrian Год назад

    Thanks alot for the content #Will :)

  • @kumarbhaskar2312
    @kumarbhaskar2312 2 года назад

    You have not covered migration topics.

  • @Rilex037
    @Rilex037 2 года назад +1

    this video is deprecates since the release of sequelize-typescript

    • @jorgegarnicablanco8136
      @jorgegarnicablanco8136 2 года назад

      Why am I reading this after finishing the f**** tutorial? xD

    • @codypotter93
      @codypotter93 2 года назад

      No. sequelize-typescript is not affiliated with Sequelize. That said there is more updated documentation for typescript support on sequelize's website.

  • @CptBongue
    @CptBongue 3 года назад +1

    26:51 There has to be a better way than having to add these attributes 3 times

    • @willjw3717
      @willjw3717  3 года назад

      Copying and pasting would have sped the process up for sure.

  • @sigmacoolbeatz7237
    @sigmacoolbeatz7237 3 года назад

    Btw, using `sequelize.sync()` is not advised. Sequelize encourage the use of the CLI to run migration or seeders

    • @willjw3717
      @willjw3717  3 года назад +2

      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.

  • @nahueljj
    @nahueljj 2 года назад +1

    when build app /config/config.js not work..GG

  • @iamalexbrady
    @iamalexbrady 2 года назад

    Thanks

  • @TaismDG
    @TaismDG Год назад

    COYG

  • @ianvieira283
    @ianvieira283 3 года назад

    that's the best

  • @diamante9161
    @diamante9161 2 года назад

    29:00 Asociations