Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions InfoLogger/lib/services/QueryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ class QueryService {
const criteriaString = this._getCriteriaAsString(criteria);
const requestRows = `SELECT * FROM \`messages\` ${criteriaString} ORDER BY \`TIMESTAMP\` LIMIT ?;`;
const queryValues = [...values, limit];
const queryAsString = processPreparedSQLStatement(requestRows, values, limit);
const startTime = Date.now(); // ms

this._logger.debugMessage(`SQL to execute: ${processPreparedSQLStatement(requestRows, values, limit)}`);
this._logger.debugMessage(`SQL to execute: ${queryAsString}`);

let rows = [];
let connection = null;
Expand Down Expand Up @@ -144,7 +145,7 @@ class QueryService {
count: rows.length,
limit: limit,
time: totalTime, // ms
queryAsString: this._getSQLQueryAsString(criteriaString, limit),
queryAsString,
};
}

Expand Down Expand Up @@ -186,16 +187,6 @@ class QueryService {
return criteria && criteria.length ? `WHERE ${criteria.join(' AND ')}` : '';
}

/**
* Get the SQL Query used as a string
* @param {string} criteriaVerbose - criteria as string in SQL format
* @param {number} limit - limit of number of messages
* @returns {string} - SQL Query as string
*/
_getSQLQueryAsString(criteriaVerbose, limit) {
return `SELECT * FROM \`messages\` ${criteriaVerbose} ORDER BY \`TIMESTAMP\` LIMIT ${limit}`;
}

/**
* Translates `filters` from client side to SQL condition to put on WHERE clause
*
Expand Down
5 changes: 3 additions & 2 deletions InfoLogger/test/lib/services/mocha-query-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,9 @@ describe('\'QueryService\' test suite', () => {
});

it('should successfully return result when filters are provided for querying', async () => {
const query = 'SELECT * FROM `messages` WHERE `timestamp`>=? AND `timestamp`<=? AND `hostname` = ? '
+ 'AND NOT(`hostname` = ? AND `hostname` IS NOT NULL) AND `severity` IN (?) ORDER BY `TIMESTAMP` LIMIT 10';
const query = 'SELECT * FROM `messages` WHERE `timestamp`>=\'1563794601.351\' AND `timestamp`<=\'1563794661.354\' '
+ 'AND `hostname` = \'test\' AND NOT(`hostname` = \'testEx\' AND `hostname` IS NOT NULL) '
+ 'AND `severity` IN (\'D\',\'W\') ORDER BY `TIMESTAMP` LIMIT 10;';

const sqlDataSource = new QueryService();
const connection = {
Expand Down
Loading