connection pooling using mysql2/promise because the connection is not released, finally mysql will report a Can"t create more than max_prepared_stmt_count statements error, so how does it release the connection?
my code looks like this
1. Create a connection
const mysql = require("mysql2/promise")
var connection = mysql.createPool(mysqlConfig)
global.connection = connection
2. Mount the link to ctx
app.use(async (ctx, next) => {
ctx.mysqlConection = global.connection
// console.log(global.connection, "99999999999")
ctx.controller = controller
ctx.service = service
ctx.are = are
ctx.iz = iz
ctx.rules = rules.rules
ctx.model = mongodb.mongoose.models;
await next()
ctx.mysqlConection.end()
})```
3. controller
findUv: async function (ctx) {
let condition = ctx.request.body
let sql = `SELECT count AS uv FROM gugudai_count ORDER BY id ASC LIMIT 1`
console.log("******************2",ctx.mysqlConection.getConnection)
const [rows, fields] = await ctx.mysqlConection.execute(sql)
// let conne=await ctx.mysqlConection.getConnection;
// console.log(conne)
return { rows }
},