use sql connection pool to help with script stalling;
This commit is contained in:
@@ -24,14 +24,17 @@ exports.findByName = function(fieldName, days, cb) {
|
||||
// console.log("findByName(" +fieldName + ",?" + days +")" );
|
||||
// days = days|365;
|
||||
console.log("findByName(" +fieldName + "," + days +")" );
|
||||
con.query("SELECT * FROM devicemessages WHERE (field_name=? OR ? IS NULL) AND (timestamp >= ( CURDATE() - INTERVAL ? DAY ))",
|
||||
[fieldName, fieldName, days], (err, data) => {
|
||||
if (!err) {
|
||||
cb(null, data);
|
||||
} else {
|
||||
cb(new Error('SQL Error: ' + err));
|
||||
}
|
||||
pool.getConnection(function(err, con) {
|
||||
if (err) throw err; // not connected!
|
||||
con.query("SELECT * FROM devicemessages WHERE (field_name=? OR ? IS NULL) AND (timestamp >= ( CURDATE() - INTERVAL ? DAY ))", [fieldName, fieldName, days], (err, data) => {
|
||||
con.release();
|
||||
if (!err) {
|
||||
cb(null, data);
|
||||
} else {
|
||||
cb(new Error('SQL Error: ' + err));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,7 +42,7 @@ 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());`;
|
||||
pool.getConnection(function(err, conn) {
|
||||
pool.getConnection(function(err, con) {
|
||||
if (err) throw err; // not connected!
|
||||
con.query(sql,params,(err, r) => {
|
||||
con.release();
|
||||
|
||||
Reference in New Issue
Block a user