ezway2mysql

0.0.7 • Public • Published

#ezway2mysql

简单的方式访问 mysql,方便 koa 进行调用, 使用了 mysql 库。

使用方式

npm i --save ezway2mysql

API

query

输入参数: sql, params

ezway2mysql.query('select * from table where id>?', [1]);

list

参数: table, conditions {cols:[...], limit:1, skip:0, where:'', params:[...], orderBy: ''}

insert

参数:table, model

update (仅支持主键为 id 自增的表)

参数:table, model

updateBatch

load

count

sum

conditions 里增加 col 参数,这个是需要统计的值

loadByKV

输入 table, key, value

loadById

输入 table, id

寻找列 id 的值是 id 的对象。

koaMiddleware

示例

在 koa 的启动文件中:

var db = require('ezway2mysql');
db.connect({
             connectionLimit: 10,
             host           : '10.163.11.23',
             user           : 'xxx',
             password       : 'xxx',
             database       : 'xxx'
           });
db.debug = true;

调用:

yield db.load("tablename", {
      where : "id=?",
      cols  : ["id", "nick", "email"],
      params: [1]
    });

koa 的 CRUD 中间键

无需编写代码,实现 crud, 完全透明操作数据库,慎用慎用!

Dependencies (2)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i ezway2mysql

    Weekly Downloads

    1

    Version

    0.0.7

    License

    Apache-2.0

    Last publish

    Collaborators

    • cloudbeer