try to fix the "Query after fatal error" problem
This commit is contained in:
@@ -1,13 +1,23 @@
|
||||
//devicemessages
|
||||
var mysql = require('mysql');
|
||||
var con = mysql.createConnection({
|
||||
var pool = mysql.createPool({
|
||||
connectionLimit : 20,
|
||||
host : 'localhost',
|
||||
user : 'iot',
|
||||
password : '!iot_popovi',
|
||||
database : 'iot'
|
||||
});
|
||||
// var con = mysql.createConnection({
|
||||
// host : 'localhost',
|
||||
// user : 'iot',
|
||||
// password : '!iot_popovi',
|
||||
// database : 'iot'
|
||||
// });
|
||||
|
||||
//const got = require('got');
|
||||
pool.on('acquire', function (connection) {
|
||||
console.log('Connection %d acquired', connection.threadId);
|
||||
});
|
||||
|
||||
exports.findByName = function(fieldName, days, cb) {
|
||||
process.nextTick(function() {
|
||||
@@ -29,15 +39,19 @@ exports.insert = function(device_id, field_name, value, cb){
|
||||
var params = [device_id, field_name,value];
|
||||
let sql = `INSERT INTO devicemessages(device_id,field_name,field_value,timestamp)
|
||||
VALUES (?,?,?,NOW());`;
|
||||
con.query(sql,params,(err, r) => {
|
||||
//if(!cb) {return;}
|
||||
if (err) {
|
||||
console.log("error: ", err);
|
||||
cb && cb(new Error('SQL Error: ' + err));
|
||||
}else{
|
||||
console.log("inserted record: ", { id: r.insertId});
|
||||
cb && cb(null, { id: r.insertId, ...params });
|
||||
}
|
||||
pool.getConnection(function(err, conn) {
|
||||
if (err) throw err; // not connected!
|
||||
con.query(sql,params,(err, r) => {
|
||||
con.release();
|
||||
//if(!cb) {return;}
|
||||
if (err) {
|
||||
console.log("error: ", err);
|
||||
cb && cb(new Error('SQL Error: ' + err));
|
||||
}else{
|
||||
console.log("inserted record: ", { id: r.insertId});
|
||||
cb && cb(null, { id: r.insertId, ...params });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.getFromDht = function(url, cb)
|
||||
@@ -56,4 +70,4 @@ exports.getFromDht = function(url, cb)
|
||||
cb && cb(new Error('SQL Error: ' + ex));
|
||||
}
|
||||
})();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user