egg-sutando-mysql
v1.1.2
Published
egg集成sutando使用mysql的插件
Downloads
4
Maintainers
Readme
egg-sutando-mysql
Install
$ npm i egg-sutando-mysql --save
Usage
本插件是对sutando的封装,用于egg开发 具体的使用文档可以查看sutando文档
// {app_root}/config/plugin.js
exports.sutando = {
enable: true,
package: 'egg-sutando-mysql',
};
Configuration
Single Database
// {app_root}/config/config.default.js
exports.sutando = {
client: {
// name: 'db1', 如果不传,则使用database的值
host: '127.0.0.1',
port: 3306,
user: 'root',
password: 123456,
database: 'db1',
},
};
Multi Databases
exports.sutando = {
clients: {
db1: {
// name: 'db1', 如果不传,则使用database的值
host: '127.0.0.1',
port: 3306,
user: 'root',
password: 123456,
database: 'db1',
},
db2: {
// name: 'db2', 如果不传,则使用database的值
host: '127.0.0.1',
port: 3306,
user: 'root',
password: 123456,
database: 'db2',
},
},
};
Example
By Table
app/service/user.js
await this.app.db1.table('users').first();
By Model
app/model/user.js
const { Model } = require('sutando');
class User extends Model {
perPage = 20;
connection = 'db1'; // 使用config配置中的name
}
module.exports = User;
app/service/user.js
await this.model.User.query();
// 支持多层级,假如user.js目录是 app/model/user/user.js
await this.model.User.User.query(); // 模型名和层级名使用 需要首字母大写
Questions & Suggestions
Please open an issue here.