Javascript can';不要在egg.js框架中使用egg mysql
在我的nodejs程序中,我使用egg.js framework创建了一个API服务器。我使用egg mysql对我的数据库进行了crud,下面是我不理解的错误代码。并且在ctx.app的声明中没有mysql nodejs版本:12.16.1, npm版本:6.14.3 {“code”:“ERR_INVALID_ARG_TYPE”,“message”:“string”参数必须是string类型或Buffer或ArrayBuffer.Received undefined”,“stack”:“TypeError[ERR_INVALID_ARG_TYPE]:“string”参数必须是string类型或Buffer或ArrayBuffer.byteLength(Buffer.js:713:11)函数处接收的未定义的\n在respond(/root/workspace/node_modules/koa/lib/application.js:261:25)\n在handleResponse(/root/workspace/node_modules/koa/lib/application.js:164:34)\n在processTicksAndRejections(internal/process/task_queues.js:97:5)”,“name:“类型错误”,“状态”:500} 这是我的配置文件Javascript can';不要在egg.js框架中使用egg mysql,javascript,mysql,node.js,npm,Javascript,Mysql,Node.js,Npm,在我的nodejs程序中,我使用egg.js framework创建了一个API服务器。我使用egg mysql对我的数据库进行了crud,下面是我不理解的错误代码。并且在ctx.app的声明中没有mysql nodejs版本:12.16.1, npm版本:6.14.3 {“code”:“ERR_INVALID_ARG_TYPE”,“message”:“string”参数必须是string类型或Buffer或ArrayBuffer.Received undefined”,“stack”:“Typ
//config/plugin.js
'use strict';
/** @type Egg.EggPlugin */
exports.mysql = {
enable: true,
package: 'egg-mysql',
};
//config/config.default.js
module.exports = appInfo => {
const config = exports = {}
config.mysql = {
client: {
host: 'localhost',
port: '3306',
user: 'aichechaoshi',
password: 'Aiche123',
database: 'aichechaoshi_db',
},
app: true,
agent: false,
};
// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1585128324727_7762';
// add your middleware config here
config.middleware = [];
// add your user config here
const userConfig = {
// myAppName: 'egg',
};
return {
...config,
...userConfig,
};
};
在用文件
//app/service/mysql.js
async read() {
const { ctx } = this;
const result = await ctx.app.mysql.select('2019_09_zhouqi_brand');
return result;
}
需要帮助