constructor(config) { super(); this.config = { database: process.env.CUBEJS_DB_NAME, ...config }; if (!this.config.db) { this.config.db = new sqlite3.Database(this.config.database); } }
function createBot(req, res, next) { logger.winston.info('Bot.createBot'); db.run('insert into bots(bot_name, bot_config, output_folder)' + 'values (?,?,?)', [req.body.bot_name, req.body.bot_config, req.body.output_folder], function(err) { if (err) { logger.winston.error("Error inserting a new record"); } else { res.status(200).json({ status: 'success', message: 'Inserted' }); } }); }
function setDBSchemaVersion(error) { if (error) { db.run("UPDATE version set version = ?", global.db_schema); logger.winston.info("Database Schema updated to v" + global.db_schema + " "); } else { db.run("INSERT into version (version) values (?)", global.db_schema); logger.winston.info("Database Schema v" + global.db_schema + " created"); } }
function getConversations(req, res, next) { logger.winston.info('Conversations.getConversations'); db.all('select * from conversations where bot_id = ? order by timestamp desc', req.params.bot_id, function(err, data) { if (err) { logger.winston.error(err); } else { res.status(200).json(data); } }); }
function getIntentsMostUsed(req, res, next) { const bot_id = req.params.bot_id; db.any('select * from intents_most_used where bot_id=$1', bot_id) .then(function (data) { res.status(200) .json(data); }) .catch(function (err) { return next(err); }); }
function updateSetting(req, res, next) { logger.winston.info('settings.updateSetting'); db.run('update settings set setting_value = ? where setting_name = ?', [req.body.setting_value, req.body.setting_name], function(err) { if (err) { logger.winston.error("Error updating the record"); } else { res.status(200).json({ status: 'success', message: 'Updated' }); } }); }
function updateEntity(req, res, next) { logger.winston.info('entities.updateEntity'); db.run('update entities set entity_name = ?, slot_data_type = ? where entity_id = ?', [req.body.entity_name, req.body.slot_data_type, req.params.entity_id], function(err) { if (err) { logger.winston.error("Error updating the record"); } else { res.status(200).json({ status: 'success', message: 'Updated' }); } }); }
function updateRegex(req, res, next) { logger.winston.info('regex.updateRegex'); db.run('update regex set regex_name = ?, regex_pattern = ? where regex_id = ?', [req.body.regex_name, req.body.regex_pattern, req.body.regex_id], function(err) { if (err) { logger.winston.error("Error updating the record"); } else { res.status(200).json({ status: 'success', message: 'Updated' }); } }); }
function createConversation(req, res, next) { logger.winston.info('Conversations.createConversation'); db.run('insert into conversations(bot_id)' + 'values (?)', [req.body.bot_id], function(err) { if (err) { logger.winston.error("Error inserting a new record"); } else { res.status(200).json({ status: 'success', message: 'Inserted' }); } }); }
function createResponse(req, res, next) { logger.winston.info('responses.createResponse'); db.run('insert into responses (response_text, action_id, response_type)' + 'values (?,?,?)', [req.body.response_text, req.body.action_id, req.body.response_type], function(err) { if (err) { logger.winston.error("Error inserting a new record"); } else { res.status(200).json({ status: 'success', message: 'Inserted' }); } }); }
function getBotIntents(req, res, next) { logger.winston.info('intents.getBotIntents'); db.all('select * from intents where bot_id = ? order by intent_id desc', req.params.bot_id, function(err, data) { if (err) { logger.winston.error(err);; } else { res.status(200).json(data); } }); }
function getBotRegex(req, res, next) { logger.winston.info('regex.getBotRegex'); db.all('select * from regex where bot_id = ? order by regex_id desc', req.params.bot_id, function(err, data) { if (err) { logger.winston.error(err); } else { res.status(200).json(data); } }); }