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