huafua-mysql

1.0.1 • Public • Published

huafua-mysql

1. 简介

本package是一套据库工具,用于操作(CRUD)mysql

2. 安装

yarn add huafua-mysql -Snpm install huafua-mysql -S

3. api说明

  • find(tablename,selections,where,limit):Promise:查询
    • tablename: 表名
    • selections:投影,选择哪些字段
    • where:查询条件,支持如eq/gt/ge/lt/le/between
    • limit:从第几条取多少条
  • remove(tablename,where):Promise:删除
    • tablename: 表名
    • where:查询条件,支持如eq/gt/ge/lt/le/between
  • update(tablename,where,updateItem):Promise:更新
    • tablename: 表名
    • where:查询条件,支持如eq/gt/ge/lt/le/between
    • updateItem:更新项目
  • 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);
    })

Readme

Keywords

Package Sidebar

Install

npm i huafua-mysql

Weekly Downloads

16

Version

1.0.1

License

MIT

Unpacked Size

30.1 kB

Total Files

11

Last publish

Collaborators

  • huafua