Answer the question
In order to leave comments, you need to log in
NodeJS + MySQL: Cannot enqueue Query after invoking quit.?
var mysql = require('mysql');
class DB {
constructor(){
this.connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '123',
database : 'test',
socketPath: '/Applications/MAMP/tmp/mysql/mysql.sock'
});
this.connection.config.queryFormat = (query, values) => {
if (!values) return query;
return query.replace(/\:(\w+)/g, (txt, key) => {
if (values.hasOwnProperty(key)) {
return mysql.escape(values[key]);
}
return txt;
});
};
this.connection.connect();
}
query(q, params, callback){
var _this = this;
this.connection.query(q, params, (err, rows, fields) => {
_this.connection.end();
callback(err, rows, fields);
});
}
}
module.exports = DB;
Error: Cannot enqueue Query after invoking quit.
_this.connection.end();
.
Answer the question
In order to leave comments, you need to log in
Why such cumbersome constructions, maybe you should use KnexJS ?
Yes, and you are not creating a poll, and this is not very good.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question