课程: Databases for Node.js Developers

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Setting up the database connection

Setting up the database connection

- [Instructor] To start using Sequelize with MySQL, we first need to install the necessary packages. So I already opened my terminal, I terminated our application, and now I type npm install sequelize, and also, mysql2. This install Sequelize, the ORM we'll use to interact with the database, and mysql2, the driver Sequelize uses to connect to MySQL. Now I will start my app again by running npm run dev. And with these installed, we are ready to set up the database connection in our Fastify application. And you will see that it's fairly similar to what we did with MongoDB, and that's a good sign because this means that we are consistent in the way we are doing things. So what we will do here is we will connect Fastify to MySQL by completing the Sequelize plugin that is already in our project. This plugin will handle connecting to MySQL using Sequelize and make the connection available across the app. But before we do this, and that's, again, similar to what we did with MongoDB, I go…

内容