Sequelize 常用操作详解及实例代码
更新时间:2016年11月21日 11:31:29 作者:bugall
这篇文章主要介绍了Sequelize 常用操作详解及实例代码的相关资料,希望能帮助到大家,需要的朋友可以参考下
Sequelize 常用操作demo
链接
var Sequelize = require('sequelize');
var sequelize = new Sequelize('nodejs', 'root', '', {host : '127.0.0.1', port : '3306', dialect : 'mysql'});
查询
Task.findAll({limit : 10, age:{gt:3},order : 'id asc'}, {raw : true, logging : true, plain : false}).on('success', function(res){
console.log(res);
}).on('failure', function(err){
console.log(err);
})
统计
Task.count({where : {title : 'test_title_1'}}, {logging : false}).on('success', function(i){
console.log(i);
}).on('failure', function(err){
console.log(err);
});
最大或最小
Task.max('id').on('success', function(max){
console.log(max);
}).on('failure', function(err){
console.log(err);
});
插入
Task.build({title : 'test_title_3', 'description' : 'test_description_3'}).save().on('success', function(msg){
console.log(msg);
}).on('failure', function(err){
console.log(err);
});
Task.create({title : 'test_title_4', 'description' : 'test_description_4'}).on('success', function(msg){
console.log(msg);
}).on('failure', function(err){
console.log(err);
});
修改
Task.update({description : 'test_description_2000'}, {id : '2'}).on('success', function(msg){
console.log(msg);
}).on('failure', function(err){
console.log(err);
});
删除
Task.destroy({id : '4'}).on('success', function(msg){
console.log(msg);
}).on('failure', function(err){
console.log(err);
});
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关文章
Spring Data JPA使用Sort进行排序(Using Sort)
本篇文章主要介绍了Spring Data JPA使用Sort进行排序(Using Sort),具有一定的参考价值,有兴趣的可以了解一下2017-07-07
springboot web项目中 Set-Cookie 失败原因及解决办法
这篇文章主要介绍了springboot web项目中 Set-Cookie 失败原因及解决办法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-10-10


最新评论