updates
This commit is contained in:
@@ -1,77 +1,77 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
const updateApiSchemaFromLocalDb = require("../query/update-api-schema-from-local-db");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* Add `users` table to user database
|
||||
* ==============================================================================
|
||||
*
|
||||
* @param {object} params - Single object passed
|
||||
* @param {import("../../types/database-schema.td").DSQL_DatabaseSchemaType} params.dbSchema - Database Schema Object
|
||||
*
|
||||
* @returns {Promise<*>} new user auth object payload
|
||||
*/
|
||||
module.exports = async function addUsersTableToDb({ dbSchema }) {
|
||||
/**
|
||||
* Initialize
|
||||
*
|
||||
* @description Initialize
|
||||
*/
|
||||
const database = process.env.DSQL_DB_NAME || "";
|
||||
/** @type {import("../../types/database-schema.td").DSQL_TableSchemaType} */
|
||||
const userPreset = require("./data/presets/users.json");
|
||||
|
||||
try {
|
||||
/**
|
||||
* Fetch user
|
||||
*
|
||||
* @description Fetch user from db
|
||||
*/
|
||||
const userSchemaMainFilePath = path.resolve(process.cwd(), "dsql.schema.json");
|
||||
let targetDatabase = dbSchema;
|
||||
|
||||
let existingTableIndex = targetDatabase.tables.findIndex((table, index) => {
|
||||
if (table.tableName === "users") {
|
||||
existingTableIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (existingTableIndex >= 0) {
|
||||
targetDatabase.tables[existingTableIndex] = userPreset;
|
||||
} else {
|
||||
targetDatabase.tables.push(userPreset);
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${userSchemaMainFilePath}`, JSON.stringify(dbSchema, null, 4), "utf8");
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
await updateApiSchemaFromLocalDb();
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
const updateApiSchemaFromLocalDb = require("../query/update-api-schema-from-local-db");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* Add `users` table to user database
|
||||
* ==============================================================================
|
||||
*
|
||||
* @param {object} params - Single object passed
|
||||
* @param {import("../../types/database-schema.td").DSQL_DatabaseSchemaType} params.dbSchema - Database Schema Object
|
||||
*
|
||||
* @returns {Promise<*>} new user auth object payload
|
||||
*/
|
||||
module.exports = async function addUsersTableToDb({ dbSchema }) {
|
||||
/**
|
||||
* Initialize
|
||||
*
|
||||
* @description Initialize
|
||||
*/
|
||||
const database = process.env.DSQL_DB_NAME || "";
|
||||
/** @type {import("../../types/database-schema.td").DSQL_TableSchemaType} */
|
||||
const userPreset = require("./data/presets/users.json");
|
||||
|
||||
try {
|
||||
/**
|
||||
* Fetch user
|
||||
*
|
||||
* @description Fetch user from db
|
||||
*/
|
||||
const userSchemaMainFilePath = path.resolve(process.cwd(), "dsql.schema.json");
|
||||
let targetDatabase = dbSchema;
|
||||
|
||||
let existingTableIndex = targetDatabase.tables.findIndex((table, index) => {
|
||||
if (table.tableName === "users") {
|
||||
existingTableIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (existingTableIndex >= 0) {
|
||||
targetDatabase.tables[existingTableIndex] = userPreset;
|
||||
} else {
|
||||
targetDatabase.tables.push(userPreset);
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${userSchemaMainFilePath}`, JSON.stringify(dbSchema, null, 4), "utf8");
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
await updateApiSchemaFromLocalDb();
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
+257
-257
File diff suppressed because it is too large
Load Diff
@@ -1,73 +1,73 @@
|
||||
[
|
||||
{
|
||||
"title": "VARCHAR",
|
||||
"name": "VARCHAR",
|
||||
"value": "0-255",
|
||||
"argument": true,
|
||||
"description": "Varchar is simply letters and numbers within the range 0 - 255",
|
||||
"maxValue": 255
|
||||
},
|
||||
{
|
||||
"title": "TINYINT",
|
||||
"name": "TINYINT",
|
||||
"value": "0-100",
|
||||
"description": "TINYINT means Integers: 0 to 100",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "SMALLINT",
|
||||
"name": "SMALLINT",
|
||||
"value": "0-255",
|
||||
"description": "SMALLINT means Integers: 0 to 240933",
|
||||
"maxValue": 32767
|
||||
},
|
||||
{
|
||||
"title": "MEDIUMINT",
|
||||
"name": "MEDIUMINT",
|
||||
"value": "0-255",
|
||||
"description": "MEDIUMINT means Integers: 0 to 1245568545560",
|
||||
"maxValue": 8388607
|
||||
},
|
||||
{
|
||||
"title": "INT",
|
||||
"name": "INT",
|
||||
"value": "0-255",
|
||||
"description": "INT means Integers: 0 to 12560",
|
||||
"maxValue": 2147483647
|
||||
},
|
||||
{
|
||||
"title": "BIGINT",
|
||||
"name": "BIGINT",
|
||||
"value": "0-255",
|
||||
"description": "BIGINT means Integers: 0 to 1245569056767568545560",
|
||||
"maxValue": 2e63
|
||||
},
|
||||
{
|
||||
"title": "TINYTEXT",
|
||||
"name": "TINYTEXT",
|
||||
"value": "0-255",
|
||||
"description": "Text with 255 max characters",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "TEXT",
|
||||
"name": "TEXT",
|
||||
"value": "0-100",
|
||||
"description": "MEDIUMTEXT is just text with max length 16,777,215",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "MEDIUMTEXT",
|
||||
"name": "MEDIUMTEXT",
|
||||
"value": "0-255",
|
||||
"description": "MEDIUMTEXT is just text with max length 16,777,215",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "LONGTEXT",
|
||||
"name": "LONGTEXT",
|
||||
"value": "0-255",
|
||||
"description": "LONGTEXT is just text with max length 4,294,967,295",
|
||||
"maxValue": 127
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
"title": "VARCHAR",
|
||||
"name": "VARCHAR",
|
||||
"value": "0-255",
|
||||
"argument": true,
|
||||
"description": "Varchar is simply letters and numbers within the range 0 - 255",
|
||||
"maxValue": 255
|
||||
},
|
||||
{
|
||||
"title": "TINYINT",
|
||||
"name": "TINYINT",
|
||||
"value": "0-100",
|
||||
"description": "TINYINT means Integers: 0 to 100",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "SMALLINT",
|
||||
"name": "SMALLINT",
|
||||
"value": "0-255",
|
||||
"description": "SMALLINT means Integers: 0 to 240933",
|
||||
"maxValue": 32767
|
||||
},
|
||||
{
|
||||
"title": "MEDIUMINT",
|
||||
"name": "MEDIUMINT",
|
||||
"value": "0-255",
|
||||
"description": "MEDIUMINT means Integers: 0 to 1245568545560",
|
||||
"maxValue": 8388607
|
||||
},
|
||||
{
|
||||
"title": "INT",
|
||||
"name": "INT",
|
||||
"value": "0-255",
|
||||
"description": "INT means Integers: 0 to 12560",
|
||||
"maxValue": 2147483647
|
||||
},
|
||||
{
|
||||
"title": "BIGINT",
|
||||
"name": "BIGINT",
|
||||
"value": "0-255",
|
||||
"description": "BIGINT means Integers: 0 to 1245569056767568545560",
|
||||
"maxValue": 2e63
|
||||
},
|
||||
{
|
||||
"title": "TINYTEXT",
|
||||
"name": "TINYTEXT",
|
||||
"value": "0-255",
|
||||
"description": "Text with 255 max characters",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "TEXT",
|
||||
"name": "TEXT",
|
||||
"value": "0-100",
|
||||
"description": "MEDIUMTEXT is just text with max length 16,777,215",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "MEDIUMTEXT",
|
||||
"name": "MEDIUMTEXT",
|
||||
"value": "0-255",
|
||||
"description": "MEDIUMTEXT is just text with max length 16,777,215",
|
||||
"maxValue": 127
|
||||
},
|
||||
{
|
||||
"title": "LONGTEXT",
|
||||
"name": "LONGTEXT",
|
||||
"value": "0-255",
|
||||
"description": "LONGTEXT is just text with max length 4,294,967,295",
|
||||
"maxValue": 127
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
[
|
||||
{
|
||||
"fieldName": "id",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true,
|
||||
"primaryKey": true,
|
||||
"autoIncrement": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
]
|
||||
[
|
||||
{
|
||||
"fieldName": "id",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true,
|
||||
"primaryKey": true,
|
||||
"autoIncrement": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"fieldName": "string",
|
||||
"dataType": "BIGINT",
|
||||
"nullValue": true,
|
||||
"primaryKey": true,
|
||||
"autoIncrement": true,
|
||||
"defaultValue": "CURRENT_TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP",
|
||||
"notNullValue": true,
|
||||
"foreignKey": {
|
||||
"foreignKeyName": "Name",
|
||||
"destinationTableName": "Table Name",
|
||||
"destinationTableColumnName": "Column Name",
|
||||
"cascadeDelete": true,
|
||||
"cascadeUpdate": true
|
||||
}
|
||||
}
|
||||
{
|
||||
"fieldName": "string",
|
||||
"dataType": "BIGINT",
|
||||
"nullValue": true,
|
||||
"primaryKey": true,
|
||||
"autoIncrement": true,
|
||||
"defaultValue": "CURRENT_TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP",
|
||||
"notNullValue": true,
|
||||
"foreignKey": {
|
||||
"foreignKeyName": "Name",
|
||||
"destinationTableName": "Table Name",
|
||||
"destinationTableColumnName": "Column Name",
|
||||
"cascadeDelete": true,
|
||||
"cascadeUpdate": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,132 +1,132 @@
|
||||
{
|
||||
"tableName": "users",
|
||||
"tableFullName": "Users",
|
||||
"fields": [
|
||||
{
|
||||
"fieldName": "id",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true,
|
||||
"primaryKey": true,
|
||||
"autoIncrement": true
|
||||
},
|
||||
{
|
||||
"fieldName": "first_name",
|
||||
"dataType": "VARCHAR(100)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "last_name",
|
||||
"dataType": "VARCHAR(100)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "email",
|
||||
"dataType": "VARCHAR(200)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "phone",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "user_type",
|
||||
"dataType": "VARCHAR(20)",
|
||||
"defaultValue": "default"
|
||||
},
|
||||
{
|
||||
"fieldName": "username",
|
||||
"dataType": "VARCHAR(100)",
|
||||
"nullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "password",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "image",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"defaultValue": "/images/user_images/user-preset.png"
|
||||
},
|
||||
{
|
||||
"fieldName": "image_thumbnail",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"defaultValue": "/images/user_images/user-preset-thumbnail.png"
|
||||
},
|
||||
{
|
||||
"fieldName": "address",
|
||||
"dataType": "VARCHAR(255)"
|
||||
},
|
||||
{
|
||||
"fieldName": "city",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "state",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "country",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "zip_code",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "social_login",
|
||||
"dataType": "TINYINT",
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldName": "social_platform",
|
||||
"dataType": "VARCHAR(50)",
|
||||
"nullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "social_id",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"nullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "more_user_data",
|
||||
"dataType": "BIGINT",
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldName": "verification_status",
|
||||
"dataType": "TINYINT",
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
"tableName": "users",
|
||||
"tableFullName": "Users",
|
||||
"fields": [
|
||||
{
|
||||
"fieldName": "id",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true,
|
||||
"primaryKey": true,
|
||||
"autoIncrement": true
|
||||
},
|
||||
{
|
||||
"fieldName": "first_name",
|
||||
"dataType": "VARCHAR(100)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "last_name",
|
||||
"dataType": "VARCHAR(100)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "email",
|
||||
"dataType": "VARCHAR(200)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "phone",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "user_type",
|
||||
"dataType": "VARCHAR(20)",
|
||||
"defaultValue": "default"
|
||||
},
|
||||
{
|
||||
"fieldName": "username",
|
||||
"dataType": "VARCHAR(100)",
|
||||
"nullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "password",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "image",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"defaultValue": "/images/user_images/user-preset.png"
|
||||
},
|
||||
{
|
||||
"fieldName": "image_thumbnail",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"defaultValue": "/images/user_images/user-preset-thumbnail.png"
|
||||
},
|
||||
{
|
||||
"fieldName": "address",
|
||||
"dataType": "VARCHAR(255)"
|
||||
},
|
||||
{
|
||||
"fieldName": "city",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "state",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "country",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "zip_code",
|
||||
"dataType": "VARCHAR(50)"
|
||||
},
|
||||
{
|
||||
"fieldName": "social_login",
|
||||
"dataType": "TINYINT",
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldName": "social_platform",
|
||||
"dataType": "VARCHAR(50)",
|
||||
"nullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "social_id",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"nullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "more_user_data",
|
||||
"dataType": "BIGINT",
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldName": "verification_status",
|
||||
"dataType": "TINYINT",
|
||||
"defaultValue": "0"
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_created_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated",
|
||||
"dataType": "VARCHAR(250)",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_code",
|
||||
"dataType": "BIGINT",
|
||||
"notNullValue": true
|
||||
},
|
||||
{
|
||||
"fieldName": "date_updated_timestamp",
|
||||
"dataType": "TIMESTAMP",
|
||||
"defaultValueLiteral": "CURRENT_TIMESTAMP"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Convert Camel Joined Text to Camel Spaced Text
|
||||
* ==============================================================================
|
||||
* @description this function takes a camel cased text without spaces, and returns
|
||||
* a camel-case-spaced text
|
||||
*
|
||||
* @param {string} text - text string without spaces
|
||||
*
|
||||
* @returns {string | null}
|
||||
*/
|
||||
function camelJoinedtoCamelSpace(text) {
|
||||
if (!text?.match(/./)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (text?.match(/ /)) {
|
||||
return text;
|
||||
}
|
||||
|
||||
if (text) {
|
||||
let textArray = text.split("");
|
||||
|
||||
let capIndexes = [];
|
||||
|
||||
for (let i = 0; i < textArray.length; i++) {
|
||||
const char = textArray[i];
|
||||
|
||||
if (i === 0) continue;
|
||||
if (char.match(/[A-Z]/)) {
|
||||
capIndexes.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
let textChunks = [`${textArray[0].toUpperCase()}${text.substring(1, capIndexes[0])}`];
|
||||
|
||||
for (let j = 0; j < capIndexes.length; j++) {
|
||||
const capIndex = capIndexes[j];
|
||||
if (capIndex === 0) continue;
|
||||
|
||||
const startIndex = capIndex + 1;
|
||||
const endIndex = capIndexes[j + 1];
|
||||
|
||||
textChunks.push(`${textArray[capIndex].toUpperCase()}${text.substring(startIndex, endIndex)}`);
|
||||
}
|
||||
|
||||
return textChunks.join(" ");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = camelJoinedtoCamelSpace;
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* Convert Camel Joined Text to Camel Spaced Text
|
||||
* ==============================================================================
|
||||
* @description this function takes a camel cased text without spaces, and returns
|
||||
* a camel-case-spaced text
|
||||
*
|
||||
* @param {string} text - text string without spaces
|
||||
*
|
||||
* @returns {string | null}
|
||||
*/
|
||||
function camelJoinedtoCamelSpace(text) {
|
||||
if (!text?.match(/./)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (text?.match(/ /)) {
|
||||
return text;
|
||||
}
|
||||
|
||||
if (text) {
|
||||
let textArray = text.split("");
|
||||
|
||||
let capIndexes = [];
|
||||
|
||||
for (let i = 0; i < textArray.length; i++) {
|
||||
const char = textArray[i];
|
||||
|
||||
if (i === 0) continue;
|
||||
if (char.match(/[A-Z]/)) {
|
||||
capIndexes.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
let textChunks = [`${textArray[0].toUpperCase()}${text.substring(1, capIndexes[0])}`];
|
||||
|
||||
for (let j = 0; j < capIndexes.length; j++) {
|
||||
const capIndex = capIndexes[j];
|
||||
if (capIndex === 0) continue;
|
||||
|
||||
const startIndex = capIndex + 1;
|
||||
const endIndex = capIndexes[j + 1];
|
||||
|
||||
textChunks.push(`${textArray[capIndex].toUpperCase()}${text.substring(startIndex, endIndex)}`);
|
||||
}
|
||||
|
||||
return textChunks.join(" ");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = camelJoinedtoCamelSpace;
|
||||
|
||||
+112
-112
@@ -1,112 +1,112 @@
|
||||
// @ts-check
|
||||
|
||||
const generateColumnDescription = require("./generateColumnDescription");
|
||||
const supplementTable = require("./supplementTable");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
module.exports = async function createTable({ dbFullName, tableName, tableInfoArray, varDatabaseDbHandler, dbSchema }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
const finalTable = supplementTable({ tableInfoArray: tableInfoArray });
|
||||
|
||||
/**
|
||||
* Grab Schema
|
||||
*
|
||||
* @description Grab Schema
|
||||
*/
|
||||
const createTableQueryArray = [];
|
||||
|
||||
createTableQueryArray.push(`CREATE TABLE IF NOT EXISTS \`${tableName}\` (`);
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
let primaryKeySet = false;
|
||||
let foreignKeys = [];
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
for (let i = 0; i < finalTable.length; i++) {
|
||||
const column = finalTable[i];
|
||||
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, foreignKey, updatedField } = column;
|
||||
|
||||
if (foreignKey) {
|
||||
foreignKeys.push({
|
||||
fieldName: fieldName,
|
||||
...foreignKey,
|
||||
});
|
||||
}
|
||||
|
||||
let { fieldEntryText, newPrimaryKeySet } = generateColumnDescription({ columnData: column, primaryKeySet: primaryKeySet });
|
||||
|
||||
primaryKeySet = newPrimaryKeySet;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (fieldName?.match(/updated_timestamp/i)) {
|
||||
fieldEntryText += " ON UPDATE CURRENT_TIMESTAMP";
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
const comma = (() => {
|
||||
if (foreignKeys[0]) return ",";
|
||||
if (i === finalTable.length - 1) return "";
|
||||
return ",";
|
||||
})();
|
||||
|
||||
createTableQueryArray.push(" " + fieldEntryText + comma);
|
||||
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
if (foreignKeys[0]) {
|
||||
foreignKeys.forEach((foreighKey, index, array) => {
|
||||
const { fieldName, destinationTableName, destinationTableColumnName, cascadeDelete, cascadeUpdate, foreignKeyName } = foreighKey;
|
||||
|
||||
const comma = (() => {
|
||||
if (index === foreignKeys.length - 1) return "";
|
||||
return ",";
|
||||
})();
|
||||
|
||||
createTableQueryArray.push(` CONSTRAINT \`${foreignKeyName}\` FOREIGN KEY (\`${fieldName}\`) REFERENCES \`${destinationTableName}\`(${destinationTableColumnName})${cascadeDelete ? " ON DELETE CASCADE" : ""}${cascadeUpdate ? " ON UPDATE CASCADE" : ""}${comma}`);
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
createTableQueryArray.push(`) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`);
|
||||
|
||||
const createTableQuery = createTableQueryArray.join("\n");
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
const newTable = await varDatabaseDbHandler({
|
||||
queryString: createTableQuery,
|
||||
database: dbFullName,
|
||||
});
|
||||
|
||||
return newTable;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
// @ts-check
|
||||
|
||||
const generateColumnDescription = require("./generateColumnDescription");
|
||||
const supplementTable = require("./supplementTable");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
module.exports = async function createTable({ dbFullName, tableName, tableInfoArray, varDatabaseDbHandler, dbSchema }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
const finalTable = supplementTable({ tableInfoArray: tableInfoArray });
|
||||
|
||||
/**
|
||||
* Grab Schema
|
||||
*
|
||||
* @description Grab Schema
|
||||
*/
|
||||
const createTableQueryArray = [];
|
||||
|
||||
createTableQueryArray.push(`CREATE TABLE IF NOT EXISTS \`${tableName}\` (`);
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
let primaryKeySet = false;
|
||||
let foreignKeys = [];
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
for (let i = 0; i < finalTable.length; i++) {
|
||||
const column = finalTable[i];
|
||||
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, foreignKey, updatedField } = column;
|
||||
|
||||
if (foreignKey) {
|
||||
foreignKeys.push({
|
||||
fieldName: fieldName,
|
||||
...foreignKey,
|
||||
});
|
||||
}
|
||||
|
||||
let { fieldEntryText, newPrimaryKeySet } = generateColumnDescription({ columnData: column, primaryKeySet: primaryKeySet });
|
||||
|
||||
primaryKeySet = newPrimaryKeySet;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (fieldName?.match(/updated_timestamp/i)) {
|
||||
fieldEntryText += " ON UPDATE CURRENT_TIMESTAMP";
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
const comma = (() => {
|
||||
if (foreignKeys[0]) return ",";
|
||||
if (i === finalTable.length - 1) return "";
|
||||
return ",";
|
||||
})();
|
||||
|
||||
createTableQueryArray.push(" " + fieldEntryText + comma);
|
||||
|
||||
////////////////////////////////////////
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
if (foreignKeys[0]) {
|
||||
foreignKeys.forEach((foreighKey, index, array) => {
|
||||
const { fieldName, destinationTableName, destinationTableColumnName, cascadeDelete, cascadeUpdate, foreignKeyName } = foreighKey;
|
||||
|
||||
const comma = (() => {
|
||||
if (index === foreignKeys.length - 1) return "";
|
||||
return ",";
|
||||
})();
|
||||
|
||||
createTableQueryArray.push(` CONSTRAINT \`${foreignKeyName}\` FOREIGN KEY (\`${fieldName}\`) REFERENCES \`${destinationTableName}\`(${destinationTableColumnName})${cascadeDelete ? " ON DELETE CASCADE" : ""}${cascadeUpdate ? " ON UPDATE CASCADE" : ""}${comma}`);
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
createTableQueryArray.push(`) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;`);
|
||||
|
||||
const createTableQuery = createTableQueryArray.join("\n");
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
const newTable = await varDatabaseDbHandler({
|
||||
queryString: createTableQuery,
|
||||
database: dbFullName,
|
||||
});
|
||||
|
||||
return newTable;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
+173
-157
@@ -1,157 +1,173 @@
|
||||
/** # MODULE TRACE
|
||||
======================================================================
|
||||
* Detected 8 files that call this module. The files are listed below:
|
||||
======================================================================
|
||||
* `require` Statement Found in [noDatabaseDbHandler.js](d:\GitHub\dsql\engine\engine\utils\noDatabaseDbHandler.js)
|
||||
* `require` Statement Found in [varDatabaseDbHandler.js](d:\GitHub\dsql\engine\engine\utils\varDatabaseDbHandler.js)
|
||||
* `require` Statement Found in [addDbEntry.js](d:\GitHub\dsql\engine\query\utils\addDbEntry.js)
|
||||
* `require` Statement Found in [deleteDbEntry.js](d:\GitHub\dsql\engine\query\utils\deleteDbEntry.js)
|
||||
* `require` Statement Found in [runQuery.js](d:\GitHub\dsql\engine\query\utils\runQuery.js)
|
||||
* `require` Statement Found in [updateDbEntry.js](d:\GitHub\dsql\engine\query\utils\updateDbEntry.js)
|
||||
* `require` Statement Found in [githubLogin.js](d:\GitHub\dsql\engine\user\social\utils\githubLogin.js)
|
||||
* `require` Statement Found in [googleLogin.js](d:\GitHub\dsql\engine\user\social\utils\googleLogin.js)
|
||||
==== MODULE TRACE END ==== */
|
||||
|
||||
// @ts-check
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
const fs = require("fs");
|
||||
const mysql = require("mysql");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
|
||||
const connection = mysql.createConnection({
|
||||
host: process.env.DSQL_HOST,
|
||||
user: process.env.DSQL_USER,
|
||||
database: process.env.DSQL_DB_NAME,
|
||||
password: process.env.DSQL_PASS,
|
||||
charset: "utf8mb4",
|
||||
port: process.env.DSQL_PORT?.match(/.../) ? parseInt(process.env.DSQL_PORT) : undefined,
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Main DB Handler Function
|
||||
* ==============================================================================
|
||||
* @async
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {string} params.query - Query String
|
||||
* @param {(string | number)[]} [params.values] - Values
|
||||
* @param {import("../../../types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema
|
||||
* @param {string} [params.database] - Target Database
|
||||
* @param {string} [params.tableName] - Target Table Name
|
||||
*
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
module.exports = async function dbHandler({ query, values, database, dbSchema, tableName }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let changeDbError;
|
||||
|
||||
if (database) {
|
||||
connection.changeUser({ database: database }, (error) => {
|
||||
if (error) {
|
||||
console.log("DB handler error in switching database:", error.message);
|
||||
changeDbError = error.message;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (changeDbError) {
|
||||
return { error: changeDbError };
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
results = await new Promise((resolve, reject) => {
|
||||
if (values?.[0]) {
|
||||
connection.query(query, values, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log("DB handler error with values array:", error.message);
|
||||
console.log("SQL:", error.sql);
|
||||
console.log("State:", error.sqlState, error.sqlMessage);
|
||||
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
} else {
|
||||
connection.query(query, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log("DB handler error:", error.message);
|
||||
console.log("SQL:", error.sql);
|
||||
console.log("State:", error.sqlState, error.sqlMessage);
|
||||
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("DB handler error:", error.message);
|
||||
|
||||
results = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
// if (results && dbSchema && tableName) {
|
||||
// const tableSchema = dbSchema.tables.find((table) => table.tableName === tableName);
|
||||
// const parsedResults = parseDbResults({
|
||||
// unparsedResults: results,
|
||||
// tableSchema: tableSchema,
|
||||
// });
|
||||
|
||||
// return parsedResults;
|
||||
// } else
|
||||
if (results) {
|
||||
return results;
|
||||
} else {
|
||||
console.log("DSQL DB handler no results received for Query =>", query);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
/** # MODULE TRACE
|
||||
======================================================================
|
||||
* Detected 8 files that call this module. The files are listed below:
|
||||
======================================================================
|
||||
* `require` Statement Found in [noDatabaseDbHandler.js](d:\GitHub\dsql\engine\engine\utils\noDatabaseDbHandler.js)
|
||||
* `require` Statement Found in [varDatabaseDbHandler.js](d:\GitHub\dsql\engine\engine\utils\varDatabaseDbHandler.js)
|
||||
* `require` Statement Found in [addDbEntry.js](d:\GitHub\dsql\engine\query\utils\addDbEntry.js)
|
||||
* `require` Statement Found in [deleteDbEntry.js](d:\GitHub\dsql\engine\query\utils\deleteDbEntry.js)
|
||||
* `require` Statement Found in [runQuery.js](d:\GitHub\dsql\engine\query\utils\runQuery.js)
|
||||
* `require` Statement Found in [updateDbEntry.js](d:\GitHub\dsql\engine\query\utils\updateDbEntry.js)
|
||||
* `require` Statement Found in [githubLogin.js](d:\GitHub\dsql\engine\user\social\utils\githubLogin.js)
|
||||
* `require` Statement Found in [googleLogin.js](d:\GitHub\dsql\engine\user\social\utils\googleLogin.js)
|
||||
==== MODULE TRACE END ==== */
|
||||
|
||||
// @ts-check
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
const fs = require("fs");
|
||||
const mysql = require("mysql");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
|
||||
const connection = mysql.createConnection({
|
||||
host: process.env.DSQL_HOST,
|
||||
user: process.env.DSQL_USER,
|
||||
database: process.env.DSQL_DB_NAME,
|
||||
password: process.env.DSQL_PASS,
|
||||
charset: "utf8mb4",
|
||||
port: process.env.DSQL_PORT?.match(/.../)
|
||||
? parseInt(process.env.DSQL_PORT)
|
||||
: undefined,
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Main DB Handler Function
|
||||
* ==============================================================================
|
||||
* @async
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {string} params.query - Query String
|
||||
* @param {(string | number)[]} [params.values] - Values
|
||||
* @param {import("../../../types/database-schema.td").DSQL_DatabaseSchemaType} [params.dbSchema] - Database Schema
|
||||
* @param {string} [params.database] - Target Database
|
||||
* @param {string} [params.tableName] - Target Table Name
|
||||
*
|
||||
* @returns {Promise<*>}
|
||||
*/
|
||||
module.exports = async function dbHandler({
|
||||
query,
|
||||
values,
|
||||
database,
|
||||
dbSchema,
|
||||
tableName,
|
||||
}) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let changeDbError;
|
||||
|
||||
console.log(connection.config);
|
||||
|
||||
if (database) {
|
||||
connection.changeUser({ database: database }, (error) => {
|
||||
if (error) {
|
||||
console.log(
|
||||
"DB handler error in switching database:",
|
||||
error.message
|
||||
);
|
||||
changeDbError = error.message;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (changeDbError) {
|
||||
return { error: changeDbError };
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
results = await new Promise((resolve, reject) => {
|
||||
if (values?.[0]) {
|
||||
connection.query(query, values, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log(
|
||||
"DB handler error with values array:",
|
||||
error.message
|
||||
);
|
||||
console.log("SQL:", error.sql);
|
||||
console.log("State:", error.sqlState, error.sqlMessage);
|
||||
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
} else {
|
||||
connection.query(query, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log("DB handler error:", error.message);
|
||||
console.log("SQL:", error.sql);
|
||||
console.log("State:", error.sqlState, error.sqlMessage);
|
||||
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("DB handler error:", error.message);
|
||||
|
||||
results = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
// if (results && dbSchema && tableName) {
|
||||
// const tableSchema = dbSchema.tables.find((table) => table.tableName === tableName);
|
||||
// const parsedResults = parseDbResults({
|
||||
// unparsedResults: results,
|
||||
// tableSchema: tableSchema,
|
||||
// });
|
||||
|
||||
// return parsedResults;
|
||||
// } else
|
||||
if (results) {
|
||||
return results;
|
||||
} else {
|
||||
console.log("DSQL DB handler no results received for Query =>", query);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/**
|
||||
* 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$/;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
module.exports = defaultFieldsRegexp;
|
||||
/**
|
||||
* 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$/;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
module.exports = defaultFieldsRegexp;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
const mysql = require("mysql");
|
||||
|
||||
/**
|
||||
* @param {mysql.Connection} connection - the active MYSQL connection
|
||||
*/
|
||||
function endConnection(connection) {
|
||||
if (connection.state !== "disconnected") {
|
||||
connection.end((err) => {
|
||||
console.log(err?.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = endConnection;
|
||||
// @ts-check
|
||||
|
||||
const mysql = require("mysql");
|
||||
|
||||
/**
|
||||
* @param {mysql.Connection} connection - the active MYSQL connection
|
||||
*/
|
||||
function endConnection(connection) {
|
||||
if (connection.state !== "disconnected") {
|
||||
connection.end((err) => {
|
||||
console.log(err?.message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = endConnection;
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
// @ts-check
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* Generate SQL text for Field
|
||||
* ==============================================================================
|
||||
* @param {object} params - Single object params
|
||||
* @param {import("../../../types/database-schema.td").DSQL_FieldSchemaType} params.columnData - Field object
|
||||
* @param {boolean} [params.primaryKeySet] - Table Name(slug)
|
||||
*
|
||||
* @returns {{fieldEntryText: string, newPrimaryKeySet: boolean}}
|
||||
*/
|
||||
module.exports = function generateColumnDescription({ columnData, primaryKeySet }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, notNullValue } = columnData;
|
||||
|
||||
let fieldEntryText = "";
|
||||
|
||||
fieldEntryText += `\`${fieldName}\` ${dataType}`;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (nullValue) {
|
||||
fieldEntryText += " DEFAULT NULL";
|
||||
} else if (defaultValueLiteral) {
|
||||
fieldEntryText += ` DEFAULT ${defaultValueLiteral}`;
|
||||
} else if (defaultValue) {
|
||||
fieldEntryText += ` DEFAULT '${defaultValue}'`;
|
||||
} else if (notNullValue) {
|
||||
fieldEntryText += ` NOT NULL`;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (primaryKey && !primaryKeySet) {
|
||||
fieldEntryText += " PRIMARY KEY";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (autoIncrement) {
|
||||
fieldEntryText += " AUTO_INCREMENT";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
return { fieldEntryText, newPrimaryKeySet: primaryKeySet || false };
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
// @ts-check
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* Generate SQL text for Field
|
||||
* ==============================================================================
|
||||
* @param {object} params - Single object params
|
||||
* @param {import("../../../types/database-schema.td").DSQL_FieldSchemaType} params.columnData - Field object
|
||||
* @param {boolean} [params.primaryKeySet] - Table Name(slug)
|
||||
*
|
||||
* @returns {{fieldEntryText: string, newPrimaryKeySet: boolean}}
|
||||
*/
|
||||
module.exports = function generateColumnDescription({ columnData, primaryKeySet }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, notNullValue } = columnData;
|
||||
|
||||
let fieldEntryText = "";
|
||||
|
||||
fieldEntryText += `\`${fieldName}\` ${dataType}`;
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (nullValue) {
|
||||
fieldEntryText += " DEFAULT NULL";
|
||||
} else if (defaultValueLiteral) {
|
||||
fieldEntryText += ` DEFAULT ${defaultValueLiteral}`;
|
||||
} else if (defaultValue) {
|
||||
fieldEntryText += ` DEFAULT '${defaultValue}'`;
|
||||
} else if (notNullValue) {
|
||||
fieldEntryText += ` NOT NULL`;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (primaryKey && !primaryKeySet) {
|
||||
fieldEntryText += " PRIMARY KEY";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
if (autoIncrement) {
|
||||
fieldEntryText += " AUTO_INCREMENT";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
return { fieldEntryText, newPrimaryKeySet: primaryKeySet || false };
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const dbHandler = require("./dbHandler");
|
||||
const mysql = require("mysql");
|
||||
const endConnection = require("./endConnection");
|
||||
|
||||
const connection = mysql.createConnection({
|
||||
host: process.env.DSQL_HOST,
|
||||
user: process.env.DSQL_USER,
|
||||
password: process.env.DSQL_PASS,
|
||||
charset: "utf8mb4",
|
||||
port: process.env.DSQL_PORT?.match(/.../) ? parseInt(process.env.DSQL_PORT) : undefined,
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
/**
|
||||
* Create database from Schema Function
|
||||
* ==============================================================================
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {string} params.query - Query String
|
||||
* @param {string[]} [params.values] - Values
|
||||
*
|
||||
* @returns {Promise<object[] | null>}
|
||||
*/
|
||||
module.exports = async function noDatabaseDbHandler({ query, values }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
/** ********************* Run Query */
|
||||
results = await new Promise((resolve, reject) => {
|
||||
if (values) {
|
||||
connection.query(query, values, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log("NO-DB handler error:", error.message);
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
} else {
|
||||
connection.query(query, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log("NO-DB handler error:", error.message);
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results) {
|
||||
return results;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const dbHandler = require("./dbHandler");
|
||||
const mysql = require("mysql");
|
||||
const endConnection = require("./endConnection");
|
||||
|
||||
const connection = mysql.createConnection({
|
||||
host: process.env.DSQL_HOST,
|
||||
user: process.env.DSQL_USER,
|
||||
password: process.env.DSQL_PASS,
|
||||
charset: "utf8mb4",
|
||||
port: process.env.DSQL_PORT?.match(/.../) ? parseInt(process.env.DSQL_PORT) : undefined,
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
/**
|
||||
* Create database from Schema Function
|
||||
* ==============================================================================
|
||||
* @param {object} params - Single Param object containing params
|
||||
* @param {string} params.query - Query String
|
||||
* @param {string[]} [params.values] - Values
|
||||
*
|
||||
* @returns {Promise<object[] | null>}
|
||||
*/
|
||||
module.exports = async function noDatabaseDbHandler({ query, values }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
/** ********************* Run Query */
|
||||
results = await new Promise((resolve, reject) => {
|
||||
if (values) {
|
||||
connection.query(query, values, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log("NO-DB handler error:", error.message);
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
} else {
|
||||
connection.query(query, (error, results, fields) => {
|
||||
if (error) {
|
||||
console.log("NO-DB handler error:", error.message);
|
||||
resolve({
|
||||
error: error.message,
|
||||
});
|
||||
} else {
|
||||
resolve(JSON.parse(JSON.stringify(results)));
|
||||
}
|
||||
// setTimeout(() => {
|
||||
// endConnection(connection);
|
||||
// }, 500);
|
||||
});
|
||||
}
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("ERROR in noDatabaseDbHandler =>", error.message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results) {
|
||||
return results;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
// @ts-check
|
||||
|
||||
const decrypt = require("../../../functions/decrypt");
|
||||
// @ts-ignore
|
||||
const defaultFieldsRegexp = require("./defaultFieldsRegexp");
|
||||
|
||||
/**
|
||||
* Parse Database results
|
||||
* ==============================================================================
|
||||
* @description this function takes a database results array gotten from a DB handler
|
||||
* function, decrypts encrypted fields, and returns an updated array with no encrypted
|
||||
* fields
|
||||
*
|
||||
* @param {object} params - Single object params
|
||||
* @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>}
|
||||
*/
|
||||
module.exports = async function parseDbResults({ unparsedResults, tableSchema }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
* @type {*[]}
|
||||
*/
|
||||
let parsedResults = [];
|
||||
|
||||
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
|
||||
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
|
||||
try {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
for (let pr = 0; pr < unparsedResults.length; pr++) {
|
||||
let result = unparsedResults[pr];
|
||||
|
||||
let resultFieldNames = Object.keys(result);
|
||||
|
||||
for (let i = 0; i < resultFieldNames.length; i++) {
|
||||
const resultFieldName = resultFieldNames[i];
|
||||
let resultFieldSchema = tableSchema?.fields[i];
|
||||
|
||||
if (resultFieldName?.match(defaultFieldsRegexp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = result[resultFieldName];
|
||||
|
||||
if (typeof value !== "number" && !value) {
|
||||
// parsedResults.push(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resultFieldSchema?.encrypted && value?.match(/./)) {
|
||||
result[resultFieldName] = decrypt({ encryptedString: value, encryptionKey, encryptionSalt });
|
||||
}
|
||||
}
|
||||
|
||||
parsedResults.push(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
return parsedResults;
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("ERROR in parseDbResults Function =>", error.message);
|
||||
return unparsedResults;
|
||||
}
|
||||
};
|
||||
// @ts-check
|
||||
|
||||
const decrypt = require("../../../functions/decrypt");
|
||||
// @ts-ignore
|
||||
const defaultFieldsRegexp = require("./defaultFieldsRegexp");
|
||||
|
||||
/**
|
||||
* Parse Database results
|
||||
* ==============================================================================
|
||||
* @description this function takes a database results array gotten from a DB handler
|
||||
* function, decrypts encrypted fields, and returns an updated array with no encrypted
|
||||
* fields
|
||||
*
|
||||
* @param {object} params - Single object params
|
||||
* @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>}
|
||||
*/
|
||||
module.exports = async function parseDbResults({ unparsedResults, tableSchema }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
* @type {*[]}
|
||||
*/
|
||||
let parsedResults = [];
|
||||
|
||||
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
|
||||
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
|
||||
try {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
for (let pr = 0; pr < unparsedResults.length; pr++) {
|
||||
let result = unparsedResults[pr];
|
||||
|
||||
let resultFieldNames = Object.keys(result);
|
||||
|
||||
for (let i = 0; i < resultFieldNames.length; i++) {
|
||||
const resultFieldName = resultFieldNames[i];
|
||||
let resultFieldSchema = tableSchema?.fields[i];
|
||||
|
||||
if (resultFieldName?.match(defaultFieldsRegexp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = result[resultFieldName];
|
||||
|
||||
if (typeof value !== "number" && !value) {
|
||||
// parsedResults.push(result);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resultFieldSchema?.encrypted && value?.match(/./)) {
|
||||
result[resultFieldName] = decrypt({ encryptedString: value, encryptionKey, encryptionSalt });
|
||||
}
|
||||
}
|
||||
|
||||
parsedResults.push(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
return parsedResults;
|
||||
} catch (/** @type {*} */ error) {
|
||||
console.log("ERROR in parseDbResults Function =>", error.message);
|
||||
return unparsedResults;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
module.exports = function slugToCamelTitle(text) {
|
||||
if (text) {
|
||||
let addArray = text.split("-").filter((item) => item !== "");
|
||||
let camelArray = addArray.map((item) => {
|
||||
return item.substr(0, 1).toUpperCase() + item.substr(1).toLowerCase();
|
||||
});
|
||||
|
||||
let parsedAddress = camelArray.join(" ");
|
||||
|
||||
return parsedAddress;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
// @ts-check
|
||||
|
||||
module.exports = function slugToCamelTitle(text) {
|
||||
if (text) {
|
||||
let addArray = text.split("-").filter((item) => item !== "");
|
||||
let camelArray = addArray.map((item) => {
|
||||
return item.substr(0, 1).toUpperCase() + item.substr(1).toLowerCase();
|
||||
});
|
||||
|
||||
let parsedAddress = camelArray.join(" ");
|
||||
|
||||
return parsedAddress;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
// @ts-check
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
module.exports = function supplementTable({ tableInfoArray }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
let finalTableArray = tableInfoArray;
|
||||
const defaultFields = require("../data/defaultFields.json");
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
let primaryKeyExists = finalTableArray.filter((_field) => _field.primaryKey);
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
defaultFields.forEach((field) => {
|
||||
let fieldExists = finalTableArray.filter((_field) => _field.fieldName === field.fieldName);
|
||||
|
||||
if (fieldExists && fieldExists[0]) {
|
||||
return;
|
||||
} else if (field.fieldName === "id" && !primaryKeyExists[0]) {
|
||||
finalTableArray.unshift(field);
|
||||
} else {
|
||||
finalTableArray.push(field);
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
return finalTableArray;
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
// @ts-check
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
module.exports = function supplementTable({ tableInfoArray }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
let finalTableArray = tableInfoArray;
|
||||
const defaultFields = require("../data/defaultFields.json");
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
let primaryKeyExists = finalTableArray.filter((_field) => _field.primaryKey);
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
defaultFields.forEach((field) => {
|
||||
let fieldExists = finalTableArray.filter((_field) => _field.fieldName === field.fieldName);
|
||||
|
||||
if (fieldExists && fieldExists[0]) {
|
||||
return;
|
||||
} else if (field.fieldName === "id" && !primaryKeyExists[0]) {
|
||||
finalTableArray.unshift(field);
|
||||
} else {
|
||||
finalTableArray.push(field);
|
||||
}
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
return finalTableArray;
|
||||
};
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
+457
-457
File diff suppressed because it is too large
Load Diff
@@ -1,98 +1,98 @@
|
||||
/** # MODULE TRACE
|
||||
======================================================================
|
||||
* Detected 9 files that call this module. The files are listed below:
|
||||
======================================================================
|
||||
* `require` Statement Found in [createDbFromSchema.js](d:\GitHub\dsql\engine\engine\createDbFromSchema.js)
|
||||
* `require` Statement Found in [updateTable.js](d:\GitHub\dsql\engine\engine\utils\updateTable.js)
|
||||
* `require` Statement Found in [runQuery.js](d:\GitHub\dsql\engine\query\utils\runQuery.js)
|
||||
* `require` Statement Found in [add-user.js](d:\GitHub\dsql\engine\user\add-user.js)
|
||||
* `require` Statement Found in [get-user.js](d:\GitHub\dsql\engine\user\get-user.js)
|
||||
* `require` Statement Found in [login-user.js](d:\GitHub\dsql\engine\user\login-user.js)
|
||||
* `require` Statement Found in [reauth-user.js](d:\GitHub\dsql\engine\user\reauth-user.js)
|
||||
* `require` Statement Found in [handleSocialDb.js](d:\GitHub\dsql\engine\user\social\utils\handleSocialDb.js)
|
||||
* `require` Statement Found in [update-user.js](d:\GitHub\dsql\engine\user\update-user.js)
|
||||
==== MODULE TRACE END ==== */
|
||||
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
const dbHandler = require("./dbHandler");
|
||||
|
||||
/**
|
||||
* DB handler for specific database
|
||||
* ==============================================================================
|
||||
* @async
|
||||
* @param {object} params - Single object params
|
||||
* @param {string} params.queryString - SQL string
|
||||
* @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<*>}
|
||||
*/
|
||||
module.exports = async function varDatabaseDbHandler({ queryString, queryValuesArray, database, tableSchema }) {
|
||||
/**
|
||||
* Create Connection
|
||||
*
|
||||
* @description Create Connection
|
||||
*/
|
||||
|
||||
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
|
||||
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
* @type {*}
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
if (queryString && Array.isArray(queryValuesArray) && queryValuesArray[0]) {
|
||||
results = await dbHandler({ query: queryString, values: queryValuesArray, database: database });
|
||||
} else if (queryString && !Array.isArray(queryValuesArray)) {
|
||||
results = await dbHandler({ query: queryString, database: database });
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (error) {
|
||||
console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>", database, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results && tableSchema) {
|
||||
try {
|
||||
const unparsedResults = results;
|
||||
// deepcode ignore reDOS: <please specify a reason of ignoring this>
|
||||
const parsedResults = await parseDbResults({ unparsedResults: unparsedResults, tableSchema: tableSchema });
|
||||
return parsedResults;
|
||||
} catch (error) {
|
||||
console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>", database, error);
|
||||
return null;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else if (results) {
|
||||
return results;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
/** # MODULE TRACE
|
||||
======================================================================
|
||||
* Detected 9 files that call this module. The files are listed below:
|
||||
======================================================================
|
||||
* `require` Statement Found in [createDbFromSchema.js](d:\GitHub\dsql\engine\engine\createDbFromSchema.js)
|
||||
* `require` Statement Found in [updateTable.js](d:\GitHub\dsql\engine\engine\utils\updateTable.js)
|
||||
* `require` Statement Found in [runQuery.js](d:\GitHub\dsql\engine\query\utils\runQuery.js)
|
||||
* `require` Statement Found in [add-user.js](d:\GitHub\dsql\engine\user\add-user.js)
|
||||
* `require` Statement Found in [get-user.js](d:\GitHub\dsql\engine\user\get-user.js)
|
||||
* `require` Statement Found in [login-user.js](d:\GitHub\dsql\engine\user\login-user.js)
|
||||
* `require` Statement Found in [reauth-user.js](d:\GitHub\dsql\engine\user\reauth-user.js)
|
||||
* `require` Statement Found in [handleSocialDb.js](d:\GitHub\dsql\engine\user\social\utils\handleSocialDb.js)
|
||||
* `require` Statement Found in [update-user.js](d:\GitHub\dsql\engine\user\update-user.js)
|
||||
==== MODULE TRACE END ==== */
|
||||
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
const dbHandler = require("./dbHandler");
|
||||
|
||||
/**
|
||||
* DB handler for specific database
|
||||
* ==============================================================================
|
||||
* @async
|
||||
* @param {object} params - Single object params
|
||||
* @param {string} params.queryString - SQL string
|
||||
* @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<*>}
|
||||
*/
|
||||
module.exports = async function varDatabaseDbHandler({ queryString, queryValuesArray, database, tableSchema }) {
|
||||
/**
|
||||
* Create Connection
|
||||
*
|
||||
* @description Create Connection
|
||||
*/
|
||||
|
||||
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
|
||||
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
* @type {*}
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
if (queryString && Array.isArray(queryValuesArray) && queryValuesArray[0]) {
|
||||
results = await dbHandler({ query: queryString, values: queryValuesArray, database: database });
|
||||
} else if (queryString && !Array.isArray(queryValuesArray)) {
|
||||
results = await dbHandler({ query: queryString, database: database });
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} catch (error) {
|
||||
console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>", database, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results && tableSchema) {
|
||||
try {
|
||||
const unparsedResults = results;
|
||||
// deepcode ignore reDOS: <please specify a reason of ignoring this>
|
||||
const parsedResults = await parseDbResults({ unparsedResults: unparsedResults, tableSchema: tableSchema });
|
||||
return parsedResults;
|
||||
} catch (error) {
|
||||
console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>", database, error);
|
||||
return null;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else if (results) {
|
||||
return results;
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user