gpt4 book ai didi

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

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Sequelize 常用操作详解及实例代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

Sequelize 常用操作demo 。

链接 。

?
1
2
var Sequelize = require( 'sequelize' );
var sequelize = new Sequelize( 'nodejs' , 'root' , '' , {host : '127.0.0.1' , port : '3306' , dialect : 'mysql' });

查询 。

?
1
2
3
4
5
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);
})

统计 。

?
1
2
3
4
5
Task.count({where : {title : 'test_title_1' }}, {logging : false }).on( 'success' , function(i){
   console.log(i);
}).on( 'failure' , function(err){
   console.log(err);
});

最大或最小 。

?
1
2
3
4
5
Task.max( 'id' ).on( 'success' , function(max){
   console.log(max);
}).on( 'failure' , function(err){
   console.log(err);
});

插入 。

?
1
2
3
4
5
6
7
8
9
10
11
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);
});

修改 。

?
1
2
3
4
5
Task.update({description : 'test_description_2000' }, {id : '2' }).on( 'success' , function(msg){
   console.log(msg);
}).on( 'failure' , function(err){
   console.log(err);
});

删除 。

?
1
2
3
4
5
Task.destroy({id : '4' }).on( 'success' , function(msg){
   console.log(msg);
}).on( 'failure' , function(err){
   console.log(err);
});

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

原文链接:http://blog.csdn.net/bugall/article/details/44019601 。

最后此篇关于Sequelize 常用操作详解及实例代码的文章就讲到这里了,如果你想了解更多关于Sequelize 常用操作详解及实例代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com