egg-psyduck-mysql

1.0.1 • Public • Published

egg-psyduck-mysql

Egg plugin for mysql

安装

$ npm i egg-psyduck-mysql --save

支持的 egg 版本

egg 3.x egg 2.x egg 1.x
😁 😁

开启插件

// {app_root}/config/plugin.js
exports.mysql = {
  enable: true,
  package: "egg-psyduck-mysql",
};

配置

// {app_root}/config/config.default.js
config.mysql = {
  default: {
    port: 3306,
    charset: "utf8mb4",
    multipleStatements: true,
    connectionLimit: 100,
  },
  // 单实例
  client: {
    host: "host",
    user: "username",
    password: "password",
    database: "dbname",
  },
  // 多实例
  clients: {
    db1: {
      host: "host",
      user: "username",
      password: "password",
      database: "dbname",
    },
  },
};

示例

const db1 = app.mysql.get("db1");
// 获取数据库连接池对象
const pool = db1.pool;
// 运行 SQL
await db1.run(sql);
// 单条查询
await db1.select(sql);
// 多条查询
await db1.selects(sql);
// 插入
await db1.insert(sql);
// 更新
await db1.update(sql);
// 删除
await db1.del(sql);
// 简单事务
await db1.transaction([sql1, sql2, sql2]);

License

MIT

Package Sidebar

Install

npm i egg-psyduck-mysql

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

16.9 kB

Total Files

5

Last publish

Collaborators

  • undsky