Config调用参数存储并返回一个config对象。我需要等待初始化mysql。
const config = require('./config');
const mysql = require('serverless-mysql')(config);
exports.handler = (event, context) => {
// mysql stuff
}
答案 0 :(得分:1)
我认为您需要等待这种情况发生?
const mysql = require('serverless-mysql')(config)??
如果是,则执行以下操作:
const config = require('./config');
async function mySQLStuff() {
try{
const mysql = await require('serverless-mysql')(config);
} catch (error) {
//handle error
}
return mysql;
};
exports.handler = (event, context) => {
mySQLStuff()
.then((data) => //mysql stuff)
};