加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Sequelize 常用操作详解及实例代码

发布时间:2020-12-14 14:42:13 所属栏目:Java 来源:网络整理
导读: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

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(err){
  console.log(err);
});

修改

Task.update({description : 'test_description_2000'},{id : '2'}).on('success',function(err){
  console.log(err);
});

删除

Task.destroy({id : '4'}).on('success',function(err){
  console.log(err);
});

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读