-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
egg-mysql plugin
1 配置egg-mysql插件
cnpm install --save egg-mysqlconfig/plugin.js
'use strict';
exports.mysql = {
enable: true,
package: 'egg-mysql'
}config/config.fefault.js
module.exports = appInfo => {
const config = exports = {};
config.keys = appInfo.name + '_1586922076183_5926';
config.middleware = [];
const userConfig = {
// myAppName: 'egg',
};
// database configuration
config.mysql = {
client: {
host: 'localhost',
port: '3306',
user: 'root',
password: 'root',
database: 'egg-db',
},
app: true,
agent: false,
};
return {
...config,
...userConfig,
};
};2 测试数据库查询
- app/controller/home.js
class HomeController extends Controller {
async index() {
let result = await this.app.mysql.get("blog_type",{})
this.ctx.body = 'hi, egg ' + JSON.stringify(result);
}
}Metadata
Metadata
Assignees
Labels
No labels
