"use strict";(function(){var e=0;"use strict";var t=require("util");var i=require("events");function r(e){i.EventEmitter.call(this);if(false===this instanceof r){return new r(e)}this.setUpDb(e)}t.inherits(r,i.EventEmitter);r.prototype.setUpDb=function(e){var t=this;var i="CREATE TABLE IF NOT EXISTS device_table(seriaNo VARCHAR(32) PRIMARY KEY, deviceType VARCHAR(32), deviceModel VARCHAR(32), softVer VARCHAR(32), hardVer VARCHAR(32)); ";this.db=e;this.db.run(i);t.db.all("PRAGMA table_info(device_table)",function(e,i){var r=false;for(var n=0;n<i.length;n++){var d=i[n];if(d.name=="hardVer"){r=true}}if(r==false){t.db.run("ALTER TABLE device_table ADD COLUMN hardVer VARCHAR(32);")}})};r.prototype.InsertAndUpdateDeviceInfo=function(e,t){var i=this;var r={deviceType:typeof e.deviceType!=="undefined"?e.deviceType:"-",deviceModel:typeof e.deviceModel!=="undefined"?e.deviceModel:"-",seriaNo:typeof e.seriaNo!=="undefined"?e.seriaNo:"-",softVer:typeof e.softVer!=="undefined"?e.softVer:"-",hardVer:typeof e.hardVer!=="undefined"?e.hardVer:"-"};i.db.run("REPLACE INTO device_table(seriaNo, deviceType, deviceModel, softVer, hardVer) "+"VALUES(?, ?, ?, ?, ?);",[r.seriaNo,r.deviceType,r.deviceModel,r.softVer,r.hardVer],function(e){if(e==null){t(null)}else{t(e)}})};r.prototype.queryAllDevices=function(e){this.db.all("SELECT * FROM device_table;",function(t,i){e(t,i)})};r.prototype.deleteDevicesBySn=function(e,t){var i=this;var r="(";for(var n=0;n<e.length;n++){r+="'"+e[n]+"'"+","}r=r.substring(0,r.length-1);r+=")";console.log(r);i.db.run("DELETE FROM device_table WHERE seriaNo in "+r,function(e){if(e){t(e)}else{t(null)}})};module.exports=r})();