Update Types

This commit is contained in:
Tben 2023-08-13 15:15:32 +01:00
parent 4aa65011e3
commit 7da50b1382
9 changed files with 17 additions and 70 deletions

View File

@ -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<object | null>}
* @returns {Promise<*>}
*/
module.exports = async function dbHandler({ query, values, database }) {
/**

View File

@ -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$/;

View File

@ -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;

View File

@ -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<object[]|null>}
@ -21,6 +21,7 @@ module.exports = async function parseDbResults({ unparsedResults, tableSchema })
* Declare variables
*
* @description Declare "results" variable
* @type {*[]}
*/
let parsedResults = [];

View File

@ -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<any[]|null>}
* @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;

View File

@ -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: <please specify a reason of ignoring this>
const parsedResults = await parseDbResults({ unparsedResults: unparsedResults, tableSchema: tableSchema });
return parsedResults;
} else {
return null;
}
};

View File

@ -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<object|null>}
* @returns {Promise<*>}
*/
async function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt }) {
/**

View File

@ -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<object>}
* @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,

View File

@ -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": {