1.0.1 • Published 5 years ago
huafua-mysql v1.0.1
huafua-mysql
1. 简介
本package是一套据库工具,用于操作(CRUD)mysql
2. 安装
yarn add huafua-mysql -S或npm install huafua-mysql -S
3. api说明
find(tablename,selections,where,limit):Promise:查询tablename: 表名selections:投影,选择哪些字段where:查询条件,支持如eq/gt/ge/lt/le/betweenlimit:从第几条取多少条
remove(tablename,where):Promise:删除tablename: 表名where:查询条件,支持如eq/gt/ge/lt/le/between
update(tablename,where,updateItem):Promise:更新tablename: 表名where:查询条件,支持如eq/gt/ge/lt/le/betweenupdateItem:更新项目
insert(tablename,itemOrItems):Promise:添加tablename: 表名itemOrItems:要添加的记录或记录数组
4. 示例
4.1 添加
添加多条记录
db.insert("sss",[ {title:"测试一下"}, {title:"测试一下"}, {title:"测试一下"} ]).then(function(data){ console.log(data); }).catch(function(err){ console.log(err); });添加单条记录
db.insert("sss",{ title:"测试一下" }).then(function(data){ console.log(data); }).catch(function(err){ console.log(err); });
4.2 删除
全部删除
db.remove("sss").then(function(data){ console.log(data); }).catch(function(err){ console.log(err); })带条件的删除
db.remove("sss",{ id:SqlOperators.between(5,9) }).then(function(data){ console.log(data); }).catch(function(err){ console.log(err); })
4.3 更新
- 全部更新
db.update("sss", null, {title:"再来测试一下"} ).then(function(data){ console.log(data); }).catch(function(err){ console.log(err); }); - 带条件的更新
db.update("sss", {id:10}, {title:"再来测试一下"} ).then(function(data){ console.log(data); }).catch(function(err){ console.log(err); });
4.4 查询
- 查询id为4记录的全部字段
db.find("sss",null,{ id:4 }).then(function(data){ console.log(data); }).catch(function(err){ console.log(err); }) 查询id为4记录的title字段
db.find("sss",["title"],{ id:4 }).then(function(data){ console.log(data); }).catch(function(err){ console.log(err); })查询全部记录
db.find("sss").then(function(data){ console.log(data); }).catch(function(err){ console.log(err); })