You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//applicationMysql.js
var Sequelize = require('sequelize');
var sequelize = new Sequelize('db', 'root', 'root', {
host: 'localhost',
dialect: 'MySQL',
pool: {
max: 5,
min: 0,
idle: 10000
},
Sequelize :Sequelize
});
function ApplicationMysql(){
return sequelize;
}
module.exports = new ApplicationMysql();
生成user表
//user.js
var app = require('../server/applicationMysql.js');
User = app.define('user',{
firstName: {
type: app.Sequelize.STRING,
// field: 'first_name' // Will result in an attribute that is firstName when user facing but first_name in the database
},
lastName: {
type: app.Sequelize.STRING
}
},{
freezeTableName: true // Model tableName will be the same as the model name
});
app.sync().then(function() {
User.create({
firstName: 'qi',
lastName: 'shuo'
});
});
module.exports = User;
参考文章
一、利用Node代码,创建MYSQL数据库表
此时,连接上数据库查询一下,发现多了一张 user的表
二、MySQL表直接生成实体类
从数据库中生成实体类
The text was updated successfully, but these errors were encountered: