/var/www/myprog.com.ua/server/node/db
NameSizeModeActions
db_context.js170300644editdlrm
db_context_cameras.js51060666editdlrm
db_context_chat.js1130644editdlrm
db_context_commands.js36090666editdlrm
db_context_devices.js40580666editdlrm
db_context_events.js44960666editdlrm
db_context_hosts.js43420644editdlrm
db_context_host_config.js26580644editdlrm
db_context_places.js148850644editdlrm
db_context_scenario.js32140666editdlrm
db_context_users.js79440644editdlrm
db_context_values.js54720666editdlrm
db_context_var.js30020666editdlrm
Edit: /var/www/myprog.com.ua/server/node/db/db_context_host_config.js (2658B)
const HostConfig = require('../objects/host_config'); const log = require('../helpers/log'); module.exports = (DbContext) => { DbContext.prototype.get_host_config = async function (host_id, key) { //let t1 = new Date().microtime(true); let _self = this; let cfg = null; try { let sql = `SELECT * FROM \`hosts_config\` WHERE host_id=${host_id} AND \`key\`='${key}' LIMIT 1`; //log.debug('DbContext', 'get_value()', `SQL: ${sql}`); let result = await _self.query(sql); if(result[0]!=undefined){ if (result[0].id > 0) { cfg = new HostConfig(result[0]); } } } catch (e) { log.error('DbContext', 'get_host_config()', e); } //let t2 = new Date().microtime(true); //log.debug('DbContext', 'get_value()', `complete ${t2 - t1}`); return cfg; } DbContext.prototype.get_user_hosts_config = async function (user_id) { // TODO ------------------ let _self = this; let t1 = new Date().microtime(true); let sql = `SELECT va.* FROM \`values\` va INNER JOIN users_hosts uh ON uh.host_id=va.host_id WHERE uh.user_id='${user_id}' ORDER BY va.k, va.n LIMIT 100`; //log.debug('DbContext', 'get_user_devices()', `SQL: ${sql}`); let values = []; try { let rows = await _self.query(sql); for (row of rows) { values.push(new Value(row)); } } catch (e) { log.error('DbContext', 'get_user_values()', e); } let t2 = new Date().microtime(true); //log.debug('DbContext', 'get_user_values()', `complete ${t2 - t1}`); return values; } DbContext.prototype.update_config = async function (cfg) { //let t1 = new Date().microtime(true); let _self = this; //await this.query('START TRANSACTION'); try { let sql = _self.sql_insert_or_update(cfg, 'hosts_config'); //log.debug('DbContext', 'update_config()',`SQL: ${sql}`); let result = await _self.query(sql); if (result.insertId > 0) { cfg.id = result.insertId; } //await _self.query('COMMIT'); //let t2 = new Date().microtime(true); //log.debug('DbContext', 'update_value()',`complete ${t2 - t1}`); return cfg; } catch (e) { log.error('DbContext', 'update_config()',e); //await _self.query('ROLLBACK'); return null; } } }