加入收藏 | 设为首页 | 会员中心 | 我要投稿 甘南站长网 (https://www.0941zz.com/)- 科技、行业物联网、开发、云计算、云管理!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-30 18:05:23 所属栏目:Java 来源:互联网
导读:Sequelize常用操作demo链接varSequelize=require('sequelize');varsequelize=newSequelize('nodejs','root','',{host:'127.0.0.1',port:'3306',dialect:'mysql'});

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);
});

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

(编辑:甘南站长网)

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

    推荐文章
      热点阅读