简体   繁体   中英

How to close mySql query connection in nodejs

I am using raw mySql query for my development. I want to close the query connection after executing the query. What can I use as per my code?

My Connection Sample:

const Sequelize = require('sequelize')
const dotenv = require('dotenv');
dotenv.config();

const sequelize =
  new Sequelize(process.env.DBNAME, process.env.DBUSER, process.env.DBPASS,
    {
      host: process.env.HOST,
      port: process.env.HOST_PORT,
      dialect: 'mysql',
      operatorsAliases: 0,
      timezone: "+06:00",

      pool: {
        max: 5,
        min: 0,
        acquire: 30000,
        idle: 10000,
      }
    }
  )

module.exports = sequelize;

My Query sample:

const dbConnect = require('../database/db');

let getEmployeeData = 
      await dbConnect.query(
                  `Select * From employee where employeeId = '00001'`, 
                  {type: QueryTypes.SELECT});

return res.json({data: getEmployeeData});

Before return I want to close my query connection. As I am getting error "packets_out_of_order" after idle the connection in nodejs, so I decide to test by closing the connection.

Thanks in advance...

You can try with

dbConnect.end();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM