diff --git a/engine/engine/utils/dbHandler.js b/engine/engine/utils/dbHandler.js index d98dd18..5e921e8 100644 --- a/engine/engine/utils/dbHandler.js +++ b/engine/engine/utils/dbHandler.js @@ -6,7 +6,6 @@ const fs = require("fs"); const mysql = require("mysql"); -const endConnection = require("./endConnection"); const connection = mysql.createConnection({ host: process.env.DSQL_HOST, @@ -35,7 +34,7 @@ const connection = mysql.createConnection({ * @param {object} [params.dbSchema] - Database Schema * @param {string} [params.database] - Target Database * - * @returns {Promise} + * @returns {Promise<*>} */ module.exports = async function dbHandler({ query, values, database }) { /** diff --git a/engine/engine/utils/defaultFieldsRegexp.js b/engine/engine/utils/defaultFieldsRegexp.js index 3a9788e..f27e1bd 100644 --- a/engine/engine/utils/defaultFieldsRegexp.js +++ b/engine/engine/utils/defaultFieldsRegexp.js @@ -2,6 +2,7 @@ * Regular expression to match default fields * * @description Regular expression to match default fields + * @type {RegExp} */ const defaultFieldsRegexp = /^id$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/; diff --git a/engine/engine/utils/endConnection.js b/engine/engine/utils/endConnection.js index b38e3c0..128539c 100644 --- a/engine/engine/utils/endConnection.js +++ b/engine/engine/utils/endConnection.js @@ -5,10 +5,12 @@ const mysql = require("mysql"); /** * @param {mysql.Connection} connection - the active MYSQL connection */ -module.exports = function endConnection(connection) { +function endConnection(connection) { if (connection.state !== "disconnected") { connection.end((err) => { console.log(err?.message); }); } -}; +} + +module.exports = endConnection; diff --git a/engine/engine/utils/parseDbResults.js b/engine/engine/utils/parseDbResults.js index c402036..5ec7cb4 100644 --- a/engine/engine/utils/parseDbResults.js +++ b/engine/engine/utils/parseDbResults.js @@ -11,7 +11,7 @@ const defaultFieldsRegexp = require("./defaultFieldsRegexp"); * fields * * @param {object} params - Single object params - * @param {{}[]} params.unparsedResults - Array of data objects containing Fields(keys) + * @param {*[]} params.unparsedResults - Array of data objects containing Fields(keys) * and corresponding values of the fields(values) * @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema * @returns {Promise} @@ -21,6 +21,7 @@ module.exports = async function parseDbResults({ unparsedResults, tableSchema }) * Declare variables * * @description Declare "results" variable + * @type {*[]} */ let parsedResults = []; diff --git a/engine/engine/utils/varDatabaseDbHandler.js b/engine/engine/utils/varDatabaseDbHandler.js index 4762c7a..d87377d 100644 --- a/engine/engine/utils/varDatabaseDbHandler.js +++ b/engine/engine/utils/varDatabaseDbHandler.js @@ -13,7 +13,7 @@ const dbHandler = require("./dbHandler"); * @param {string[]} [params.queryValuesArray] - Values Array * @param {string} params.database - Database name * @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema - * @returns {Promise} + * @returns {Promise<*>} */ module.exports = async function varDatabaseDbHandler({ queryString, queryValuesArray, database, tableSchema }) { /** @@ -29,6 +29,7 @@ module.exports = async function varDatabaseDbHandler({ queryString, queryValuesA * Declare variables * * @description Declare "results" variable + * @type {*} */ let results; diff --git a/engine/engine/utils/varReadOnlyDatabaseDbHandler.js b/engine/engine/utils/varReadOnlyDatabaseDbHandler.js deleted file mode 100644 index b444895..0000000 --- a/engine/engine/utils/varReadOnlyDatabaseDbHandler.js +++ /dev/null @@ -1,57 +0,0 @@ -// @ts-check - -const fs = require("fs"); -const parseDbResults = require("./parseDbResults"); -const dbHandler = require("./dbHandler"); - -/** - * - * @param {object} param0 - * @param {string} param0.queryString - * @param {object} param0.database - * @param {object[]} [param0.queryValuesArray] - * @param {object | null} [param0.tableSchema] - * @returns - */ -module.exports = async function varReadOnlyDatabaseDbHandler({ queryString, database, queryValuesArray, tableSchema }) { - /** - * Declare variables - * - * @description Declare "results" variable - */ - let results; - - /** - * Fetch from db - * - * @description Fetch data from db if no cache - */ - try { - results = await dbHandler({ query: queryString, values: queryValuesArray, database: database }); - - //////////////////////////////////////// - } catch (/** @type {*} */ error) { - //////////////////////////////////////// - - console.log("\x1b[31mvarReadOnlyDatabaseDbHandler ERROR\x1b[0m =>", database, error.message); - - /** - * Return error - */ - return error.message; - } - - /** - * Return results - * - * @description Return results add to cache if "req" param is passed - */ - if (results) { - const unparsedResults = results; - // deepcode ignore reDOS: - const parsedResults = await parseDbResults({ unparsedResults: unparsedResults, tableSchema: tableSchema }); - return parsedResults; - } else { - return null; - } -}; diff --git a/engine/query/utils/addDbEntry.js b/engine/query/utils/addDbEntry.js index c4d95be..e1034c1 100644 --- a/engine/query/utils/addDbEntry.js +++ b/engine/query/utils/addDbEntry.js @@ -21,7 +21,7 @@ const updateDbEntry = require("./updateDbEntry"); * "Read only" or "Full Access"? Defaults to "Read Only" * @param {string} params.dbFullName - Database full name * @param {string} params.tableName - Table name - * @param {object} params.data - Data to add + * @param {*} params.data - Data to add * @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema * @param {string} [params.duplicateColumnName] - Duplicate column name * @param {string} [params.duplicateColumnValue] - Duplicate column value @@ -29,7 +29,7 @@ const updateDbEntry = require("./updateDbEntry"); * @param {string} params.encryptionKey - Update this row if it exists * @param {string} params.encryptionSalt - Update this row if it exists * - * @returns {Promise} + * @returns {Promise<*>} */ async function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt }) { /** diff --git a/engine/query/utils/runQuery.js b/engine/query/utils/runQuery.js index 0b078e1..ba7b951 100644 --- a/engine/query/utils/runQuery.js +++ b/engine/query/utils/runQuery.js @@ -5,7 +5,7 @@ const fs = require("fs"); const addDbEntry = require("./addDbEntry"); const updateDbEntry = require("./updateDbEntry"); const deleteDbEntry = require("./deleteDbEntry"); -const varReadOnlyDatabaseDbHandler = require("../../engine/utils/varReadOnlyDatabaseDbHandler"); +const varDatabaseDbHandler = require("../../engine/utils/varDatabaseDbHandler"); /** ****************************************************************************** */ /** ****************************************************************************** */ @@ -19,13 +19,13 @@ const varReadOnlyDatabaseDbHandler = require("../../engine/utils/varReadOnlyData * ============================================================================== * @param {object} params - An object containing the function parameters. * @param {string} params.dbFullName - Database full name. Eg. "datasquire_user_2_test" - * @param {string|object} params.query - Query string or object + * @param {*} params.query - Query string or object * @param {boolean} [params.readOnly] - Is this operation read only? * @param {import("../../../types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema * @param {string[]} [params.queryValuesArray] - An optional array of query values if "?" is used in the query string * @param {string} [params.tableName] - Table Name * - * @return {Promise} + * @return {Promise<{result: *, error?: *}>} */ async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName }) { /** @@ -53,7 +53,7 @@ async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArra */ try { if (typeof query === "string") { - result = await varReadOnlyDatabaseDbHandler({ + result = await varDatabaseDbHandler({ queryString: query, queryValuesArray, database: dbFullName, diff --git a/package.json b/package.json index a5d482e..500832a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.7.1", + "version": "1.7.2", "description": "Cloud-based SQL data management tool", "main": "index.js", "bin": {