安装
npm install --save sequelize
初始化使用
const { Sequelize, Model, DataTypes } = require('sequelize');
const sequelize = new Sequelize('db_stu', 'db_username', 'db_password', {
host: '127.0.0.1',
dialect: 'mysql',
pool: {
max: 50,
min: 0,
idle: 5000
}
});
测试连接
sequelize.authenticate()
(async () => {
try {
await sequelize.authenticate();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
})()
网友评论