Sequelize 常用操作详解及实例代码
时间:2021-05-07 10:49:39|栏目: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, 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);
});
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
栏 目:JAVA代码
本文地址:http://www.codeinn.net/misctech/116609.html


阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机




