mysql2 execute不返回任何响应

时间:2019-08-20 09:33:36

标签: node.js node-mysql2

这是我在teacher.js中的sql语句

var db = require('./../dba.js');

Teacher.remove = function (schoolId, id, result) {
db.execute("DELETE FROM teachers WHERE schoolId = ? AND id = ?", [schoolId, id], function (err, res) {
    if(err) {
        console.log("error in remove: ", err);
        result(null, err);
    }else{   
        console.log("teacher removed")
        result(null, res);
    }
}); 

};

由下面的代码(在teacherController.js内部)调用

exports.removeTeacher = function(schoolId,id,res,result){
  console.log('entering teacherController removeTeacher with id: ' + id + " and schoolId: " + schoolId)
  Teacher.remove(schoolId,id,function(err,data){
    if (err){
        console.log('error', err)
        return res.send(err)
    }else{
        console.log(data)
        return result(null,data)
    }
  });
};

代码执行查找没有任何问题。问题是,完成执行后,我无法获得响应。 console.log之后我所有的db.execute()都不会执行。

下面是我的dba.js中的代码,在该代码中我将连接池设置为mysql

function connection() {
  try {
    const mysql = require('mysql2');

    const pool = mysql.createPool({
      host: "mydbhost.rds.amazonaws.com",
      database: "mydb",
      user: "user",
      password: "password", 
      connectionLimit: 10,
      waitForConnections: true,
      queueLimit: 0,
      namedPlaceholders: true
    });

    const promisePool = pool.promise();

    return promisePool;
  } catch (error) {
    return console.log(`Could not connect - ${error}`);
  }
}

const pool = connection();

module.exports = {
  connection: async () => pool.getConnection(),
  execute: (...params) => pool.execute(...params)
};

我想念什么?

0 个答案:

没有答案