Models
Your models are stored in the following directory: models/your-model-name.js.
You can add as much models as you need manually.
We use different plugin depending if you are using a Relational Database such as MySQL, PostrgreSQL, SQLite or MongoDB.
MySQL, PostgreSQL, SQLite​
We use the Sequelize ORM when it comes to relational database. So you will have to represent your models using the proper syntax. For more info you can check: https://sequelize.org/master/
A Sequelize model will basically look like this:
module.exports = (sequelize, DataTypes) => {
const Cars = sequelize.define('cars', {
name: {
type: DataTypes.STRING
},
model: {
type: DataTypes.STRING
},
year: {
type: DataTypes.DATE
},
createdAt: {
type: DataTypes.DATE
},
updatedAt: {
type: DataTypes.DATE,
},
}, {
tableName: 'cars',
});
Cars.associate = (models) => {
};
return Cars;
};
MongoDB​
We use the Mongoose ODM when it comes to MongoDB. So you will have to represent your models using the proper syntax. For more info you can check: https://mongoosejs.com/docs/guide.html
A Mongoose model will basically look like this:
module.exports = (mongoose) => {
const schema = mongoose.Schema({
firstname: {
type: String,
required: true
},
lastname: {
type: String,
required: true
},
birthdate: {
type: Date,
required: true
},
rating: {
type: Number,
required: true
},
createdAt: {
type: Date,
required: true
},
updatedAt: {
type: Date,
required: true
}
});
return mongoose.model('users', schema, 'users');
};