课程: Databases for Node.js Developers

免费学习该课程!

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

Creating a user model for Sequelize

Creating a user model for Sequelize

- [Instructor] Now that we have designed our database, in this video, we will define the user model using Sequelize. This will feel familiar from what we did with MongoDB and Mongoose. So let's create our first model, and for that, I go into Source, Models, and as we have it for Mongoose, we also have a folder for Sequelize. And in there, I now create a new file, and I call it User.js, uppercase U, and this will hold a user model, and there, I start with importing the data types of Sequelize. So I write import (keys clicking) DataTypes from sequelize. (keys clicking) Next, I'm starting with exporting a default function (keys clicking) that takes sequelize as an argument. (keys clicking) And there in the function body, we will define our model, and that's really again very similar to MongoDB because in there, I now write const User = sequelize (keys clicking) and we don't have to bring in sequelize as you see, because it's coming in in line three, so it's a function parameter. And on…

内容