Sequelize的增删改查

//启动mysql数据库

net start mysql

//新建index.js

//建立连接
var Sequelize=require("sequelize");
var mysql=require("mysql");
var sequelize=new Sequelize("h5ds",'root','YES',{
host:'localhost',
dialect:'mysql',
port:3306,
pool:{
max:5,
min:0,
idle:10000
},
define:{
'underscored':true
}
})

var user=sequelize.define("h5ds_user",{
id:{type:Sequelize.INTEGER,primaryKey:true,autoIncrement: true,field:"id"},
username:{type:Sequelize.STRING,field:'username'},
password:{type:Sequelize.STRING,field:'password'},
email:{type:Sequelize.STRING,field:'email'},
usertype:{type:Sequelize.INTEGER,field:'usertype'},
tel:{type:Sequelize.STRING,field:'tel'}
},
{freezeTableName: true}
)
/*user.sync({force:false}).then(function(){
return user.create({
username:"liuhao",
password:"123",
email:"8888888",
usertype:1,
tel:"12334556"
})
}).then(function(res){
console.log("@@@@@@@@@++++"+JSON.stringify(res))
})*/
/*user.sync({force:false}).then(function(){
return user.update({
username:"liuhao666",
},{where:{
id:1
}})
}).then(function(res){
console.log("@@@@@@@@@++++"+JSON.stringify(res))
})*/

/*user.sync({force:false}).then(function(){
return user.findAll({
where:{
username:'liuhao666'
},
})
}).then(function(res){
console.log("@@@@@@@@@++++"+JSON.stringify(res))
})*/

/*user.sync({force:false}).then(function(){
return user.destroy({
where:{
username:'liuhao666'
},
})
}).then(function(res){
console.log("@@@@@@@@@++++"+JSON.stringify(res))
})*/

原文地址:https://www.cnblogs.com/liuhao-web/p/8530051.html