Learn Sequelize ORM on Node.js with MySQL From Scratch in One Video
Вставка
- Опубліковано 29 вер 2024
- Written Tutorial:
go.ipenywis.com...
💻 Github github.com/ipe...
Our Udemy Courses:
Let's Create A Nodejs Desktop Chat Application(React/Socket) :
www.udemy.com/...
-- Official Links---
Official Website: ipenywis.com
Official Facebook: go.ipenywis.com...
Official Twitter: go.ipenywis.com...
--Support US--
By Becoming a Patreon: go.ipenywis.com...
For all those who are getting error commands such as sequelize migration:generate ...,first of all install the package called 'sequelize-cli' by running `npm i sequelize-cli` or if you are using yarn,do `yarn add sequelize-cli`.After you can bootstrap by doing `npx sequelize-cli init` to have the folders model,migrations,config and seeders created for you.So,you can run either run the commande to generate a migration file or a model,or a commande to generate both a model and a migration file that you can customize.For that you can do :`npx sequelize-cli model:generate --name youmodelname --attributes att21:string,attr2:float` but you will name you model and your attributes according to your needs.To run migrations :`npx sequelize-cli db:migrate`.For more informations go to the official doc : docs.sequelizejs.com/manual/migrations.html
You can completely skip the migration part, by creating the models as shown, but instead of creating migrate scripts, just import them and call .sync() method, and it will auto-create the table for you.
its not the recommended way, but if you want something easy to follow, there you go :)
Great tutorial. You would show how to add the sequelize-hierachy plugin, I tried reading the docs but I am lost
Great Tutorial for beginners. If you don't know anything about sequelize then this video gives you very good overview and hands on. Thank you so much for this video.
Hi thanks for the video.
Can you also make a video on how to setup mysql with mariaDb like you already did in this video, i cannot figure out the installation of mysql and mariab, i get error 'Access denied for user 'root'@'localhost' (using password: NO)'. It would be really helpful.
Thanks in advance!
It gave me a lot of confidence!
very helpful sir thank you
Around the 19 minutes mark, I had to run this instead: npx sequelize migration:generate --name create_tweets_table
it's showing User.hasMany is not a function, can you help me?
ok it works like really good, but i wanted to be able to view my data in phpmyadmin also but i can't when i use postman everything works but for some reason i can't see it in phpmyadmin
thanks
You know that node.js is a javascript environment while phpmyadmin is a php environment right?
The way you pronounce 'dialect' like 'delicate' is cute yet hilariously incorrect. :)
First, thank you for this video!!! You are toggling between cap S and lower case s-equelize in const/other and that is really confusing. A long time ago on a planet far far away, I was taught that when using a sentence to define the meaning of a word, to never use the word itself or variants in the sentence. Define it using other words. You cause unnecessary confusion when you do things like const Sequelize = require("sequalize") and in another places you do....const sequelize = new Sequelize(stuff). I mean seriously, HOW does that make things clear? To me it does not. The context in each case ought to be explained and different names should be used to keep the context clear. Like const localSequelizeInstance = require("sequelize") would make learning this stuff far less confusing and assuming you are NOT teaching to folks who already know this stuff ('cause that would be pointless), then perhaps newbies, like me, could spend less time scratching our heads and more time absorbing you knowledge. I taught physics for almost 25 years and I can tell you, the first step to being a successful teacher is to realize that your first objective is to make sure your approach is not adding obstacles that obscure the process or add more confusion than students already have. I hope this is helpful. Kindest regards, Brian
Brian, I think you are very generous giving such detailed feedback; I fully agree. I am coming from Oracle and deep knowledge of SQL. I find these ORMs horrible; I am looking for a solution to output JSON.
So damn useful! Literally cleared all my doubts of working with ORM and Node.js. You explained it so beautifully and the tutorial provided is so well documented. Great work man.
Great video but sure could do with some timestamps.
Can you set up the foreign key on the Tweet model when creating it instead of modifying the migration file?
What do you need to do with migrations when you want to add an extra column to the user model later on in a live production system where you cannot drop the table?
you can add another migration, to update a table that you want to add the extra column, search "queryInterface.addColumn"
Hello.You are really doing a great job.Please do some stuff on making database level changes using sequelize when we are in already existing projects of production environment where there is need of altering tables.Because in most of the organisations the DBA people will be handling all the database related alter queries.If altered tables from their side, i have a doubt that do we need to change sequelize code in our repositories also?
How to start mysql server in visual studio command prompt, unable to get sequelize command ...
since using global is bad, what other package or method can we use
Consider working with DI paradigm framework (Dependency Injection) like Nest.js which allows you to work with Singleton instance.
" The package at "node_modules/sequelize/lib/sequelize.js" attempted to import the Node standard library module "url". It failed because React Native does not include the Node standard library"
getting this error when I'm trying to use Sequelize in React-native app.
What changes should I make?
Awesome video ++++++++++++ 🙂
I am getting the following error while using "sequelize db: migrate"
The "url" argument must be of type string. Received type object
Anyone knows how to fix this?
Thanks
Will hasMany and belongsTo modify the table after it's execution to create a relationship?
you can create model schema of tables through sequelize cli .
I've been working for inner join in sequelize for two days. I solved it thanks to you
All good. But the monotony of the voice makes me sleepy
You probably need more sleep ;-)
ua-cam.com/video/MnljgIYwiaI/v-deo.html
perfect
Is there any way to make migrations automatically like in Django?
It's a great tutorial IF you want to see it working. But for a project you basically removed one of the best scenarios of folder organization that is the one that "sequelize init" create for you and used a "single file" format what is awful even for micro projects... still a good video to "see it working" nothing more than that.
ua-cam.com/video/MnljgIYwiaI/v-deo.html
thanks for making this video, it still holds up to this day and it makes sequelize really clear!
definitely, this video is really helpful.
¿How can connect to real db? change the host for example@example.com?
Really good explanation. You actually got my interest in sequelize.
keep up my friend, u are freakin good at what u do
Great video. It is very informative.Thank you
Can you please share the source code of this??
really got my interest, how clear the explanation was! thank you a lot.
is it possible to make a video about inheritance using sequelize, thanks again.
Glad you liked it. Great suggestion!
how can I use it with APIs?
gr8t tutorial dude!
Great video, thanks!
don't get raw result [object] of `.findAll()`
Hi,
I am having following error while running migration command ($ sequelize db:migrate), can you help me fix it
ERROR: Client does not support authentication protocol requested by server; c server; consider upgrading MySQL client
have you upgraded your mysql client?
I think you need to place the same configuration parameters such as (localhost, database, username, password) from connection.js to config.json file.
[This approach resolve the issue:]
Example:
----------------------
| Config.json |
---------------------
{
"development": {
"username": "root",
"password": "abcdef",
"database": "blahblah",
"host": "127.0.0.1",
"dialect": "mysql",
"port": 8888, /* phpmyadmin port */
"dialectOptions": {
"socketPath": "/Applications/MAMP/tmp/mysql/mysql.sock" /* for linux or mac using mamp */
}
}
--------------------------
| Connection.js |
--------------------------
const Sequelize = require('sequelize');
const sequelize = new Sequelize('blahblah', 'root', 'abcdef', {
host: 'localhost',
dialect: 'mysql',
port: 8888, /* phpmyadmin port */
logging: function () {},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
dialectOptions: {
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock' /* for linux or mac using mamp */
},
define: {
paranoid: true
}
});
sequelize.authenticate().then(() => {
module.exports = sequelize;
global.sequelize = sequelize;
console.log('MYSQL connection was established successfully.');
}).catch(error => {
console.error('Unable to connect to the MYSQL Server: ', error);
}).finally(() => {
sequelize.close();
});
Great to the point. Thx
nice explaination.... appreciate it
Importing models from database
-- sequelize-automate can help you with ;)
ua-cam.com/video/MnljgIYwiaI/v-deo.html
outdated
Super helpful and crystal clear 👍🏽
RIP accent
Source code please
I keep getting User.create is not a function !!!
[ FIXED ] 2020 UPDATE : the newly generated models can bring you the error of " Error : User.create is not a function "
change the models the same as the ones this guy made,
Thanks bro
Nice one!
Thank you.
Why does sequelize fail to load the Typings in my project even when i directly specify in my json.config.
Try to install @types/sequelize
Nice, will this work if I use postgres? Are there any syntax differences?
Yes I will work with postgres without changing a line of code all you need to change is the driver dialect to postgres and your database connection settings.
how to create tree folder ?
Thank You.
thanks!!!