filmov
tv
Run Seeders with Node JS and Sequelize - Rest API with NodeJS and MySQL (2020)

Показать описание
Today we gonna Run Seeders with Node JS and Sequelize to insert some bulk set of data to the database in a single operation.
Normally, we use seeds to insert some default set of data to the database. For a example when a project is deployed we may wanna insert some default users, categories and things like that. For that we use seeders.
So, to demonstrate this, we gonna use a sequelize seeder example which is seeding some default categories to our category table.
0:00 Intro
2:31 Install and Configure Sequelize
3:01 Create a Seeder with Sequelize
7:37 Run seeder file
8:29 Undo a seed
9:40 Validate category ID when creating a post
13:47 Fix user ID with actual user ID decoded from the access token
17:18 Outro
To use seeders with nodeJS, we need an ORM (Object Relational Mapping). Which is why we use Sequelize. Seeding a MySQL database with Sequelize is quiet easy.
We can create a Seeder with the following command.
sequelize seed:generate --name category-seeder
This will create a Sequelize seeder file. Which we need to edit and enter our records we want to enter and save it.
Now, we can run that seeder with the following command.
sequelize db:seed --seed category-seeder
That's it! And if you think you made a mistake, you can always undo a seed. To undo Sequelize seed run the following command.
sequelize db:seed:undo --seed category-seeder
You can always refer the Sequelize seeder documentation to learn more about Sequelize seeders.
So, that's pretty much it in this Nodejs Sequelize seeder example.
In the previous video we Implemented Image Uploader in NodeJS API
This is the part 11 of the tutorial series, How to Create REST API with NodeJS and MySQL using Express and Sequelize.
Watch the Series from the beginning:
Connect to Database with Sequelize:
Implement CRUD with NodeJS and Sequelize
Implement Authentication with NodeJS and JsonWebToken
Hit Subscribe and smash the Like button.
Normally, we use seeds to insert some default set of data to the database. For a example when a project is deployed we may wanna insert some default users, categories and things like that. For that we use seeders.
So, to demonstrate this, we gonna use a sequelize seeder example which is seeding some default categories to our category table.
0:00 Intro
2:31 Install and Configure Sequelize
3:01 Create a Seeder with Sequelize
7:37 Run seeder file
8:29 Undo a seed
9:40 Validate category ID when creating a post
13:47 Fix user ID with actual user ID decoded from the access token
17:18 Outro
To use seeders with nodeJS, we need an ORM (Object Relational Mapping). Which is why we use Sequelize. Seeding a MySQL database with Sequelize is quiet easy.
We can create a Seeder with the following command.
sequelize seed:generate --name category-seeder
This will create a Sequelize seeder file. Which we need to edit and enter our records we want to enter and save it.
Now, we can run that seeder with the following command.
sequelize db:seed --seed category-seeder
That's it! And if you think you made a mistake, you can always undo a seed. To undo Sequelize seed run the following command.
sequelize db:seed:undo --seed category-seeder
You can always refer the Sequelize seeder documentation to learn more about Sequelize seeders.
So, that's pretty much it in this Nodejs Sequelize seeder example.
In the previous video we Implemented Image Uploader in NodeJS API
This is the part 11 of the tutorial series, How to Create REST API with NodeJS and MySQL using Express and Sequelize.
Watch the Series from the beginning:
Connect to Database with Sequelize:
Implement CRUD with NodeJS and Sequelize
Implement Authentication with NodeJS and JsonWebToken
Hit Subscribe and smash the Like button.
Комментарии