This commit is contained in:
Tben 2023-08-12 15:14:00 +01:00
parent 722f85cd4a
commit 320a271e10
4 changed files with 243 additions and 235 deletions

View File

@ -30,11 +30,13 @@ const updateTable = require("./utils/updateTable");
* @param {import("../../types/database-schema.td").DSQL_DatabaseSchemaType[]} dbSchema - An array of database schema objects
*/
async function createDbFromSchema(dbSchema) {
try {
/**
* Grab Schema
*
* @description Grab Schema
*/
console.log("Starting createDbFromSchema ...");
if (!dbSchema || !Array.isArray(dbSchema) || !dbSchema[0]) {
console.log("Invalid DB schema data");
@ -46,6 +48,8 @@ async function createDbFromSchema(dbSchema) {
const database = dbSchema[i];
const { dbFullName, tables } = database;
console.log("Now constructing database =>", database?.dbFullName);
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
@ -53,6 +57,8 @@ async function createDbFromSchema(dbSchema) {
/** @type {{ dbFullName: string }[] | null} */
const dbCheck = await noDatabaseDbHandler({ query: `SELECT SCHEMA_NAME AS dbFullName FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '${dbFullName}'` });
console.log("DB CHeck =>", dbCheck);
if (dbCheck && dbCheck[0]?.dbFullName) {
// Database Exists
} else {
@ -204,7 +210,7 @@ async function createDbFromSchema(dbSchema) {
if (!alias?.match(/./)) continue;
/**
* @type {DSQL_MYSQL_SHOW_INDEXES_Type[] | null}
* @type {any[] | null}
* @description All indexes from MYSQL db
*/
const allExistingIndexes = await varDatabaseDbHandler({
@ -243,6 +249,9 @@ async function createDbFromSchema(dbSchema) {
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
} catch (error) {
console.log("Error in createDbFromSchema => ", error.message);
}
}
/** ****************************************************************************** */

View File

@ -15,6 +15,7 @@ const connection = mysql.createConnection({
password: process.env.DSQL_PASS,
charset: "utf8mb4",
port: process.env.DSQL_PORT?.match(/.../) ? parseInt(process.env.DSQL_PORT) : undefined,
timeout: 5000,
});
//////////////////////////////////////////////////////////////////////////////////
@ -71,7 +72,6 @@ module.exports = async function dbHandler({ query, values, database }) {
*/
try {
results = await new Promise((resolve, reject) => {
if (connection.state !== "disconnected") {
if (values) {
connection.query(query, values, (error, results, fields) => {
if (error) {
@ -82,9 +82,10 @@ module.exports = async function dbHandler({ query, values, database }) {
} else {
resolve(JSON.parse(JSON.stringify(results)));
}
setTimeout(() => {
endConnection(connection);
}, 500);
// setTimeout(() => {
// endConnection(connection);
// }, 500);
});
} else {
connection.query(query, (error, results, fields) => {
@ -96,12 +97,11 @@ module.exports = async function dbHandler({ query, values, database }) {
} else {
resolve(JSON.parse(JSON.stringify(results)));
}
setTimeout(() => {
endConnection(connection);
}, 500);
// setTimeout(() => {
// endConnection(connection);
// }, 500);
});
}
}
});
////////////////////////////////////////

View File

@ -11,6 +11,7 @@ const connection = mysql.createConnection({
password: process.env.DSQL_PASS,
charset: "utf8mb4",
port: process.env.DSQL_PORT?.match(/.../) ? parseInt(process.env.DSQL_PORT) : undefined,
timeout: 5000,
});
/**
@ -38,7 +39,6 @@ module.exports = async function noDatabaseDbHandler({ query, values }) {
try {
/** ********************* Run Query */
results = await new Promise((resolve, reject) => {
if (connection.state !== "disconnected") {
if (values) {
connection.query(query, values, (error, results, fields) => {
if (error) {
@ -49,9 +49,9 @@ module.exports = async function noDatabaseDbHandler({ query, values }) {
} else {
resolve(JSON.parse(JSON.stringify(results)));
}
setTimeout(() => {
endConnection(connection);
}, 500);
// setTimeout(() => {
// endConnection(connection);
// }, 500);
});
} else {
connection.query(query, (error, results, fields) => {
@ -63,12 +63,11 @@ module.exports = async function noDatabaseDbHandler({ query, values }) {
} else {
resolve(JSON.parse(JSON.stringify(results)));
}
setTimeout(() => {
endConnection(connection);
}, 500);
// setTimeout(() => {
// endConnection(connection);
// }, 500);
});
}
}
});
////////////////////////////////////////
////////////////////////////////////////

View File

@ -1,6 +1,6 @@
{
"name": "datasquirel",
"version": "1.5.1",
"version": "1.5.2",
"description": "Cloud-based SQL data management tool",
"main": "index.js",
"bin": {