Update Types
This commit is contained in:
parent
4aa65011e3
commit
7da50b1382
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const mysql = require("mysql");
|
const mysql = require("mysql");
|
||||||
const endConnection = require("./endConnection");
|
|
||||||
|
|
||||||
const connection = mysql.createConnection({
|
const connection = mysql.createConnection({
|
||||||
host: process.env.DSQL_HOST,
|
host: process.env.DSQL_HOST,
|
||||||
@ -35,7 +34,7 @@ const connection = mysql.createConnection({
|
|||||||
* @param {object} [params.dbSchema] - Database Schema
|
* @param {object} [params.dbSchema] - Database Schema
|
||||||
* @param {string} [params.database] - Target Database
|
* @param {string} [params.database] - Target Database
|
||||||
*
|
*
|
||||||
* @returns {Promise<object | null>}
|
* @returns {Promise<*>}
|
||||||
*/
|
*/
|
||||||
module.exports = async function dbHandler({ query, values, database }) {
|
module.exports = async function dbHandler({ query, values, database }) {
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
* Regular expression to match default fields
|
* Regular expression to match default fields
|
||||||
*
|
*
|
||||||
* @description 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$/;
|
const defaultFieldsRegexp = /^id$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;
|
||||||
|
|
||||||
|
@ -5,10 +5,12 @@ const mysql = require("mysql");
|
|||||||
/**
|
/**
|
||||||
* @param {mysql.Connection} connection - the active MYSQL connection
|
* @param {mysql.Connection} connection - the active MYSQL connection
|
||||||
*/
|
*/
|
||||||
module.exports = function endConnection(connection) {
|
function endConnection(connection) {
|
||||||
if (connection.state !== "disconnected") {
|
if (connection.state !== "disconnected") {
|
||||||
connection.end((err) => {
|
connection.end((err) => {
|
||||||
console.log(err?.message);
|
console.log(err?.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
module.exports = endConnection;
|
||||||
|
@ -11,7 +11,7 @@ const defaultFieldsRegexp = require("./defaultFieldsRegexp");
|
|||||||
* fields
|
* fields
|
||||||
*
|
*
|
||||||
* @param {object} params - Single object params
|
* @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)
|
* and corresponding values of the fields(values)
|
||||||
* @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
* @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||||
* @returns {Promise<object[]|null>}
|
* @returns {Promise<object[]|null>}
|
||||||
@ -21,6 +21,7 @@ module.exports = async function parseDbResults({ unparsedResults, tableSchema })
|
|||||||
* Declare variables
|
* Declare variables
|
||||||
*
|
*
|
||||||
* @description Declare "results" variable
|
* @description Declare "results" variable
|
||||||
|
* @type {*[]}
|
||||||
*/
|
*/
|
||||||
let parsedResults = [];
|
let parsedResults = [];
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ const dbHandler = require("./dbHandler");
|
|||||||
* @param {string[]} [params.queryValuesArray] - Values Array
|
* @param {string[]} [params.queryValuesArray] - Values Array
|
||||||
* @param {string} params.database - Database name
|
* @param {string} params.database - Database name
|
||||||
* @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
* @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 }) {
|
module.exports = async function varDatabaseDbHandler({ queryString, queryValuesArray, database, tableSchema }) {
|
||||||
/**
|
/**
|
||||||
@ -29,6 +29,7 @@ module.exports = async function varDatabaseDbHandler({ queryString, queryValuesA
|
|||||||
* Declare variables
|
* Declare variables
|
||||||
*
|
*
|
||||||
* @description Declare "results" variable
|
* @description Declare "results" variable
|
||||||
|
* @type {*}
|
||||||
*/
|
*/
|
||||||
let results;
|
let results;
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
};
|
|
@ -21,7 +21,7 @@ const updateDbEntry = require("./updateDbEntry");
|
|||||||
* "Read only" or "Full Access"? Defaults to "Read Only"
|
* "Read only" or "Full Access"? Defaults to "Read Only"
|
||||||
* @param {string} params.dbFullName - Database full name
|
* @param {string} params.dbFullName - Database full name
|
||||||
* @param {string} params.tableName - Table 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 {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||||
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
||||||
* @param {string} [params.duplicateColumnValue] - Duplicate column value
|
* @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.encryptionKey - Update this row if it exists
|
||||||
* @param {string} params.encryptionSalt - 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 }) {
|
async function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt }) {
|
||||||
/**
|
/**
|
||||||
|
@ -5,7 +5,7 @@ const fs = require("fs");
|
|||||||
const addDbEntry = require("./addDbEntry");
|
const addDbEntry = require("./addDbEntry");
|
||||||
const updateDbEntry = require("./updateDbEntry");
|
const updateDbEntry = require("./updateDbEntry");
|
||||||
const deleteDbEntry = require("./deleteDbEntry");
|
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 {object} params - An object containing the function parameters.
|
||||||
* @param {string} params.dbFullName - Database full name. Eg. "datasquire_user_2_test"
|
* @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 {boolean} [params.readOnly] - Is this operation read only?
|
||||||
* @param {import("../../../types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database schema
|
* @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.queryValuesArray] - An optional array of query values if "?" is used in the query string
|
||||||
* @param {string} [params.tableName] - Table Name
|
* @param {string} [params.tableName] - Table Name
|
||||||
*
|
*
|
||||||
* @return {Promise<object>}
|
* @return {Promise<{result: *, error?: *}>}
|
||||||
*/
|
*/
|
||||||
async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName }) {
|
async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName }) {
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,7 @@ async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArra
|
|||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
if (typeof query === "string") {
|
if (typeof query === "string") {
|
||||||
result = await varReadOnlyDatabaseDbHandler({
|
result = await varDatabaseDbHandler({
|
||||||
queryString: query,
|
queryString: query,
|
||||||
queryValuesArray,
|
queryValuesArray,
|
||||||
database: dbFullName,
|
database: dbFullName,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "1.7.1",
|
"version": "1.7.2",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user