"use strict";(function(){var e=0;"use strict";var t=require("util");var s=require("events");function i(e){s.EventEmitter.call(this);if(false===this instanceof i){return new i}this.setupDb(e)}t.inherits(i,s.EventEmitter);i.prototype.setupDb=function(e){var t=this;var s="CREATE TABLE IF NOT EXISTS vsu_devices(id INTEGER PRIMARY KEY AUTOINCREMENT, deviceName VARCHAR(32),seriaNo VARCHAR(32), switchId INTEGER, role VARCHAR(15), status VARCHAR(15));";var i="CREATE TABLE IF NOT EXISTS vsu_links(id INTEGER PRIMARY KEY AUTOINCREMENT, deviceName VARCHAR(32),seriaNo VARCHAR(32), preport VARCHAR(32), prestatus INTEGER, nextport INTEGER, nextstatus INTEGER, uptime VARCHAR(32));";var r="CREATE TABLE IF NOT EXISTS vsu_ports(id INTEGER PRIMARY KEY AUTOINCREMENT, deviceName VARCHAR(32),seriaNo VARCHAR(32), portName VARCHAR(32),portStatus VARCHAR(10), ip VARCHAR(32), peerIp VARCHAR(32));";var u="CREATE TABLE IF NOT EXISTS vsu_bfds(id INTEGER PRIMARY KEY AUTOINCREMENT, deviceName VARCHAR(32), seriaNo VARCHAR(32), portName VARCHAR(32), portStatus VARCHAR(10));";this.db=e;this.db.serialize(function(){t.db.run(s);t.db.run(i);t.db.run(r);t.db.run(u)})};i.prototype.insertIntoVsuDevices=function(e,t){self.db.run("INSERT INTO vsu_devices(deviceName, seriaNo, switchId, role, status)"+"VALUES (?, ?, ?, ?, ?);",[e.deviceName,e.seriaNo,e.switchId,e.role,e.status],function(e){if(e){t(e)}else{t(null)}})};i.prototype.insertIntoVsuLinks=function(e,t){self.db.run("INSERT INTO vsu_links(deviceName, seriaNo, preport, prestatus, nextport, nextstatus, uptime)"+"VALUES (?, ?, ?, ?, ?, ?, ?);",[e.deviceName,e.seriaNo,e.preport,e.prestatus,e.nextport,e.nextstatus,e.uptime],function(e){if(e){t(e)}else{t(null)}})};i.prototype.insertIntoVsuPorts=function(e,t){self.db.run("INSERT INTO vsu_ports(deviceName, seriaNo, portName, portStatus, ip, peerIp)"+"VALUES(?, ?, ?, ?, ?, ?);",[e.deviceName,e.seriaNo,e.portName,e.portStatus,e.ip,e.peerIp],function(e){if(e){t(e)}else{t(null)}})};i.prototype.insertIntoVsuBfds=function(e,t){self.db.run("INSERT INTO vsu_bfds(deviceName, seriaNo, portName, portStatus)"+"VALUES(?, ?, ?, ?);",[e.deviceName,e.seriaNo,e.portName,e.portStatus],function(e){if(e){t(e)}else{t(null)}})};i.prototype.queryVsuBfds=function(e,t){this.db.all("SELECT * FROM vsu_bfds WHERE deviceName = ?;",[e.deviceName],function(e,s){t(e,s)})};i.prototype.queryVsuPorts=function(e,t){this.db.all("SELECT * FROM vsu_ports WHERE deviceName = ?;",[e.deviceName],function(e,s){t(e,s)})};i.prototype.queryVsuLinks=function(e,t){this.db.all("SELECT * FROM vsu_links WHERE deviceName = ?;",[e.deviceName],function(e,s){t(e,s)})};i.prototype.queryVsuDevices=function(e,t){this.db.all("SELECT * FROM vsu_devices WHERE deviceName = ?;",[e.deviceName],function(e,s){t(e,s)})};i.prototype.deleteAllVsuStatusTables=function(e,t){var s="";var i=this;s+="begin;\n";s+="DELETE FROM vsu_bfds WHERE deviceName = "+"'"+e.deviceName+"' ;\n";s+="DELETE FROM vsu_devices WHERE deviceName = "+"'"+e.deviceName+"' ;\n";s+="DELETE FROM vsu_links WHERE deviceName = "+"'"+e.deviceName+"' ;\n";s+="DELETE FROM vsu_ports WHERE deviceName = "+"'"+e.deviceName+"' ;\n";s+="commit;";i.db.exec(s,function(e){if(e){t(e)}else{t(null)}})};module.exports=i})();