How to Use Sequelize ORM in NodeJS - Tutorial

Поділитися
Вставка
  • Опубліковано 9 січ 2025

КОМЕНТАРІ • 116

  • @joshuahamann2075
    @joshuahamann2075 Рік тому +20

    9:45 "You can see that its going to give an error" - How I always feel when I'm coding. Thanks for taking the time for this tutorial.

  • @vieiratn
    @vieiratn 4 роки тому +32

    The difference between mysql and mysql2 is basically promises. The package mysql2 allows you to work with asynchronous JS. Thanks for the video bro.

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому +4

      Thanks for sharing! I actually never realized this. This can be helpful cause ive been caught in callback 'hell' situations using mysql.

  • @Alefast51
    @Alefast51 11 днів тому

    very simple and straight to the point, not everyone needs 3 hours of video tutorial, nice video!

  • @cooperathletics6278
    @cooperathletics6278 4 роки тому +6

    Concise and straight to the point! Beats these 3 hour crash course vids. Thanks for the tutorial.

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому +1

      Thank you! Really appreciate it!

    • @tekhaven
      @tekhaven 3 роки тому

      @@PedroTechnologies Awesome tutorial and very straight to the point

  • @lucylu184
    @lucylu184 3 роки тому +5

    Your videos helped me get an internship. I'm really grateful.

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +1

      Wow thats amazingg! If you don't mind, where you going to work? This makes me very happy!

  • @markokafor7432
    @markokafor7432 4 роки тому +45

    You didn’t need to install path and fs. They are built in node js modules

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому +5

      Yes

    • @angelbythewings
      @angelbythewings 3 роки тому +2

      @@PedroTechnologies Also its not require, its request and response 😄

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +6

      @@angelbythewings yep, i explained that in the past hahaha i used to call it required and response because thats how i said (in order to understand) back when i was learning. I shouldn’t have used that in the video but when i made this video i was grtting like 3 views per video so i didnt think it would matter hahaha nowadays i say request in my new videos

    • @angelbythewings
      @angelbythewings 3 роки тому +1

      @@PedroTechnologies that's completely understandable. Sorry if you already knew, I shouldn't have pointed out.
      BTW it was a very nice tutorial

    • @PedroTechnologies
      @PedroTechnologies  3 роки тому +2

      @@angelbythewings nahhh its good hahahha i really appreciate it cause other people can see it! I sometimes don’t like my old videos cause im scared that i used to say dumb stuff like this lmao

  • @triptisingla4897
    @triptisingla4897 Рік тому

    bestest video in the whole worldd, i am saying you are the best, I have been searching everywhere but here my search got results, thankksssssss

  • @anonlegion9096
    @anonlegion9096 Рік тому +5

    11:50 req does not mean "require", it means "request", the req and res in (req, res) => {...} literally means request and response
    13:55 that if(err) is redundant, the .catch() is called only if err is thrown... the only useful thing to do with conditionals inside the .catch() is handling different kinds of errors

  • @parasarora5869
    @parasarora5869 3 роки тому +4

    Amazing tutorial sir!!... you cleared my doubts regarding sequelize in one go 👍👍

  • @CourageousCreatives
    @CourageousCreatives 3 роки тому +3

    Another really great run-down on a topic! Thanks!

  • @СтепаСорокин-е2я

    You can also use Postman to test different methods like post without frontend at all 14:40

  • @tekhaven
    @tekhaven 3 роки тому +10

    Please can you do a tutorial on Table relationship? Really need that with sequelize

  • @unsolvedstories1016
    @unsolvedstories1016 Рік тому

    Beautiful and most required video 🙏

  • @uktech9432
    @uktech9432 6 місяців тому

    Honestly it was very well explained ❤.

  • @gokulkurup1584
    @gokulkurup1584 4 роки тому +1

    Really Helpful. Thanks for the great tutorial !

  • @austin96tig
    @austin96tig 4 роки тому +1

    That was a really good explanation!

  • @jabezraja9383
    @jabezraja9383 3 роки тому +1

    i really appreciate your effort... it was very usefull for me

  • @aksaurooj838
    @aksaurooj838 4 роки тому +3

    when i write sequelize init i get an error The term 'sequelize' is not recognized as the name of a cmdlet, function, script file, or
    operable program. Check the spelling of the name, or if a path was included, verify that the path is
    correct and try again.
    At line:1 char:1
    + sequelize init
    + ~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (sequelize:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    PLEASE HELP

    • @fredrickemmanuel479
      @fredrickemmanuel479 5 місяців тому

      am also getting same error

    • @blakebard
      @blakebard 5 місяців тому

      npm install -g sequelize-cli

    • @alberto5056
      @alberto5056 3 місяці тому

      I have the same error, you have to use "npx sequelize-cli init"

  • @danielkibby6601
    @danielkibby6601 Рік тому

    This is great, so I glad I found your video :D

  • @Spmdiamond
    @Spmdiamond 2 роки тому

    Love you bro thanks a lot it is best way to learn for beginners

  • @ianpropst-campbell6028
    @ianpropst-campbell6028 Рік тому

    Thank you for this helpful tutorial!

  • @k303k
    @k303k Рік тому

    Thanks for the video Pedro!

  • @Pareshbpatel
    @Pareshbpatel Рік тому

    An excellent introduction to using Sequilize to perform CRUD Operations on a mySQL database. Thanks, Pedro
    {2023-06-05}

  • @MarsTheProgrammer
    @MarsTheProgrammer 4 роки тому +3

    Thanks for the videos, i have a question. Is there a library for autocompleting sequelize syntax? I tried a few but they don't seem to work.

    • @MarsTheProgrammer
      @MarsTheProgrammer 4 роки тому +3

      nvm, i found the solution, sequelize init imports it wrong for the models.
      It should be like this:
      const { Sequelize } = require("sequelize");
      Not like this:
      const Sequelize = require("sequelize");

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому +1

      Awesome! Yeah, they are exporting Sequelize as a separate variable so to get the autocomplete you have to put the brackets. Glad you fixed it!

  • @stonecomstock
    @stonecomstock 2 роки тому

    this was very helpful! thank you

  • @Мертвыйотчим
    @Мертвыйотчим Рік тому

    thank you sir, useful and easy to understand

  • @Vir7uaLGameplays
    @Vir7uaLGameplays 2 роки тому +1

    What about connection to multiple databases? What's the best approach?
    Btw if you could make an updated version of this video it would be great because sequelize is a bit implementation is a bit different now.

    • @hyphenbruh7376
      @hyphenbruh7376 Рік тому

      Hi, I’m new to the Sequelize ORM utilities, but I imagine you would need to instantiate another instance of Sequelize and pass it your other databases’ configuration settings (i.e. name, port, password, username, etc.) The Sequelize instance in ./models/index.js in the video only creates one database object with its corresponding tables. Not sure how you would implement it using DBMS other than MySQL though.
      ps. Not sure if this is the best approach for making multiple database connections, or if this is even right at all, so take it with a grain of salt.

  • @aadarshaacharya267
    @aadarshaacharya267 4 роки тому +1

    Why do we have to pass sequelize & DataTypes ad parameter in Models. Can't we directly import from sequelize ? like const { DataTypes, Sequelize } = require('sequelize');

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому

      You could do it both ways! Passing it as a parameter is a standard for the sequelize-cli, but if your not using it than you probably should just import it!

  • @PanlasangMotour
    @PanlasangMotour 4 роки тому +1

    Thank you i learn a lot can you make it with front end an todo task application so that others can deep dive learn using with node js express pug integration

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому

      I have a an example of how to make a todo list application on my 3 part series called: CRUD Tutorial ReactJS ! I don't use sequelize on that series, but transferring the normal mysql logic to sequelize is pretty straightforward!

  • @abjzzz
    @abjzzz 2 роки тому

    Hi Pedro, how are you? I have a question, is this way of doing queries safe? Is this the frontend interfacing with the db directly? Im not sure about those things. Thank you!

  • @ibrahimacanada
    @ibrahimacanada 2 роки тому +1

    Always great thanks !!

  • @xbzq
    @xbzq Рік тому +4

    When I saw that you npm installed fs and path I realized you have no idea what you're talking about. These modules aren't packages. They are internal modules provided by nodejs itself. Thinking you need to install these demonstrates a great lack of experience with the platform.

  • @earlgrey8611
    @earlgrey8611 Рік тому

    You export your model function from User.js which is an anonymous function that takes 2 params - sequelize, DataTypes.
    I don't understand how when you then import this function as db you don't have to pass an instance of sequelize and Datatypes to it?
    How can you simply say db.sequelize.define (....) -- shouldn't you have to say db(sequelize, DataTypes).define ( ... ) ??

  • @premalatha5182
    @premalatha5182 3 роки тому

    Hi very helpful video but i have an doubt could you pls help me to update the record using sequelize

  • @HHHanant
    @HHHanant 11 місяців тому

    Hi great video, need your help in one question.
    I have two DBs in mysql. In DB1 we have person table and DB2 we have gender table.
    I have to do association between DB1.person and DB2.gender.
    can you help me with this.

  • @lg-25
    @lg-25 6 місяців тому

    How to retrieve the data use sequelize mysql when we insert execl data in database of three tables

  • @7gsReef
    @7gsReef Рік тому

    what is the application you use to see your database and know whats inside it?

  • @SmokyBigSmoke
    @SmokyBigSmoke 4 роки тому +1

    Thank You. Really helpful.

  • @maelstrom57
    @maelstrom57 6 місяців тому

    Bro, path and fs are native NodeJS modules.

  • @kishorep3376
    @kishorep3376 2 роки тому

    Cannot read properties of undefined (reading 'findAll') what can I do!

  • @yonatanshalev9428
    @yonatanshalev9428 2 роки тому

    Great tutorial, thanks! Any chance to get the GitHub repository to clone?

  • @aakarshanthapa889
    @aakarshanthapa889 3 роки тому

    Hello Pedro, I wanted to use ES6 modules for importing, but can't figure out how to change the require imports to es6 inside models/index.js file

    • @govinda399
      @govinda399 2 роки тому

      use "type" : "module" in your script file

    • @sang4005
      @sang4005 8 місяців тому

      I run into same error

  • @BrawlStars-kq9mt
    @BrawlStars-kq9mt 4 місяці тому

    I changed the .js files to ecma6, and it doesnt work. How can fix this issue?

  • @thesinged196
    @thesinged196 2 роки тому +1

    sequelize: command not found
    help me pro plssssss!!!

  • @davidanwar6996
    @davidanwar6996 4 роки тому +1

    what should i use, pure SQL or Sequelize?

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому

      It depends on what is your application. However in a Job or an advanced project, usually you would use Sequelize. Its a lot more handy to use an ORM like Sequelize because then you don't need to write actual SQL. It is a way to convert SQL to normal JavaScript, so thats why almost every company uses it.

    • @davidanwar6996
      @davidanwar6996 4 роки тому

      @@PedroTechnologies thank's .

  • @DeveenRathnayake
    @DeveenRathnayake 4 роки тому +1

    hello, I got an error when I coding with your video.
    const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
    ^
    TypeError: Class constructor model cannot be invoked without 'new'

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому +1

      Did you install 'path'? This error occurs in the file generated by the cli so that is weird hahaha I would try restarting the server!

    • @DeveenRathnayake
      @DeveenRathnayake 4 роки тому

      Yes I installed it too. Now problem is okay. I figured it out

  • @MrChilo89
    @MrChilo89 3 роки тому

    i had to use this command on bash "powershell Set-ExecutionPolicy RemoteSigned" on VS to skip the problem "cannot be loaded because running scripts is disabled on this system."

  • @theverybestdev
    @theverybestdev 4 роки тому +2

    please upload about associations in sequelize

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому +2

      This should be an interesting video idea! I will make one!

    • @theverybestdev
      @theverybestdev 4 роки тому +1

      @@PedroTechnologies awesome thanks

    • @tekhaven
      @tekhaven 3 роки тому

      @@PedroTechnologies i really need the association because i am having problems with table relationships

  • @jtcheng1805
    @jtcheng1805 3 роки тому

    I failed at step: sequelize init, return "sequelize : unrecognizable. previous step: npm install... seems ok with npm warning server@1.0.0 no description. help please

    • @jtcheng1805
      @jtcheng1805 3 роки тому +1

      fix it with npx sequelize init help from previous comments,

    • @hichamamroussi9087
      @hichamamroussi9087 Рік тому

      thank you !@@jtcheng1805

  • @josesoltero6057
    @josesoltero6057 Рік тому

    thanks so much for this video!!!

  • @Cynthia-cw6kd
    @Cynthia-cw6kd 5 місяців тому

    Love this, thanks!

  • @navinwadhwa595
    @navinwadhwa595 11 місяців тому

    Why app. Get for inserting.. It should be app.post??

  • @nathansantos4197
    @nathansantos4197 4 роки тому +1

    how can I read a database.sql file in node js?
    I need to read this in my React js project using node
    Anyone can help me?

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому

      What do you mean? You want to use an existing database or create a new one?

    • @nathansantos4197
      @nathansantos4197 4 роки тому

      @@PedroTechnologies I want to use a existing database file. I need to read this database to get some data

  • @reni2090
    @reni2090 2 місяці тому

    great video! tysm

  • @sridharkatta3461
    @sridharkatta3461 3 роки тому

    i think path and fs are inbuilt packages in nodejs so we dont need to install them

  • @mr.hassaan7785
    @mr.hassaan7785 3 роки тому +1

    please zoom the screen or increase font size. ur screen is too big, does not mean that others have the same... if i watch it on mobile, the font is too small. barely reading

  • @alexdev5734
    @alexdev5734 11 місяців тому

    Why would you want to install fs when its built-in to nodejs

    • @sang4005
      @sang4005 8 місяців тому

      I wonder too, both path and fs are built-in to nodejs

  • @instant-code
    @instant-code 4 роки тому +1

    where is next tutorial

    • @PedroTechnologies
      @PedroTechnologies  4 роки тому

      This was a long time ago, but I should probably create a new series! Sorry about that!

  • @kishore2398
    @kishore2398 2 роки тому

    How to update pls tell me brother

  • @note_to_you
    @note_to_you 3 роки тому

    how to make SELECT * FROM posts join users on posts.UserId = users.id in sequelize.

  • @tigranavagyan5922
    @tigranavagyan5922 3 роки тому

    Thank you a LOT!!!

  • @programmingwithnit5308
    @programmingwithnit5308 Рік тому

    Thank you brother

  • @ibrahimmainge
    @ibrahimmainge Рік тому

    You don't need to install fs and path.... It's core modules!

  • @matthewclarke1926
    @matthewclarke1926 Рік тому

    The ORM dream. Just write SQL.

  • @Omkara2664
    @Omkara2664 Рік тому

    Nice bro 👌👌

  • @Jeancympoycoding
    @Jeancympoycoding 4 місяці тому

    I like your videos

  • @TolaFoundationMw
    @TolaFoundationMw Рік тому

    🔥🔥🔥

  • @נתנאלנגוסה-ס3ס
    @נתנאלנגוסה-ס3ס 4 місяці тому

    thank you !!

  • @saladin_advanced
    @saladin_advanced 3 роки тому

    Thank you.

  • @pankajsuryavanshi8332
    @pankajsuryavanshi8332 Рік тому

    Build once again project.