You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to implement serverless-mysql with my serverless-express app. I'm having issues initializing serverless-mysql and then passing that connection into the main handler so I can run queries in functions that are called by the router. I found this example online that runs a setup task for connecting to a db, but I'm concerned if I implement this with serverless-mysql it won't manage the connections properly.
// lambda.js
require('source-map-support/register')
const serverlessExpress = require('@vendia/serverless-express')
const app = require('./app')
let serverlessExpressInstance
function asyncTask () {
return new Promise((resolve) => {
setTimeout(() => resolve('connected to database'), 1000)
})
}
async function setup (event, context) {
const asyncValue = await asyncTask()
console.log(asyncValue)
serverlessExpressInstance = serverlessExpress({ app })
return serverlessExpressInstance(event, context)
}
function handler (event, context) {
if (serverlessExpressInstance) return serverlessExpressInstance(event, context)
return setup(event, context)
}
exports.handler = handler
The text was updated successfully, but these errors were encountered:
In addition to this, I would need to import the serverless mysql in these other functions, which I think would try and reinitialize the mysql connection.
I am trying to implement serverless-mysql with my serverless-express app. I'm having issues initializing serverless-mysql and then passing that connection into the main handler so I can run queries in functions that are called by the router. I found this example online that runs a setup task for connecting to a db, but I'm concerned if I implement this with serverless-mysql it won't manage the connections properly.
The text was updated successfully, but these errors were encountered: