Updates
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = camelJoinedtoCamelSpace;
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function camelJoinedtoCamelSpace(text) {
|
||||
export default function camelJoinedtoCamelSpace(text) {
|
||||
if (!(text === null || text === void 0 ? void 0 : text.match(/./))) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { DSQL_TableSchemaType } from "../../types";
|
||||
import { DSQL_DATASQUIREL_USER_DATABASES } from "../../types/dsql";
|
||||
type Param = {
|
||||
tableSchema?: DSQL_TableSchemaType;
|
||||
recordedDbEntry?: DSQL_DATASQUIREL_USER_DATABASES;
|
||||
update?: boolean;
|
||||
isMain?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Handle Table Record Update and Insert
|
||||
*/
|
||||
export default function ({ tableSchema, recordedDbEntry, update, isMain, }: Param): Promise<number | undefined>;
|
||||
export {};
|
||||
@@ -0,0 +1,83 @@
|
||||
import varDatabaseDbHandler from "./varDatabaseDbHandler";
|
||||
import numberfy from "../../utils/numberfy";
|
||||
import updateDbEntry from "../../functions/backend/db/updateDbEntry";
|
||||
import addDbEntry from "../../functions/backend/db/addDbEntry";
|
||||
import slugToNormalText from "../../utils/slug-to-normal-text";
|
||||
import _ from "lodash";
|
||||
/**
|
||||
* # Handle Table Record Update and Insert
|
||||
*/
|
||||
export default async function ({ tableSchema, recordedDbEntry, update, isMain, }) {
|
||||
var _a;
|
||||
if (isMain)
|
||||
return undefined;
|
||||
let tableId;
|
||||
const targetDatabase = "datasquirel";
|
||||
const targetTableName = "user_database_tables";
|
||||
if (!(tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.tableName)) {
|
||||
return undefined;
|
||||
}
|
||||
const newTableSchema = _.cloneDeep(tableSchema);
|
||||
try {
|
||||
if (!recordedDbEntry) {
|
||||
throw new Error("Recorded Db entry not found!");
|
||||
}
|
||||
// const existingTableName = newTableSchema.tableNameOld
|
||||
// ? newTableSchema.tableNameOld
|
||||
// : newTableSchema.tableName;
|
||||
const newTableEntry = {
|
||||
user_id: recordedDbEntry.user_id,
|
||||
db_id: recordedDbEntry.id,
|
||||
db_slug: recordedDbEntry.db_slug,
|
||||
table_name: slugToNormalText(newTableSchema.tableName),
|
||||
table_slug: newTableSchema.tableName,
|
||||
child_table: newTableSchema.childTable ? 1 : 0,
|
||||
child_table_parent_database_schema_id: newTableSchema.childTableDbId
|
||||
? numberfy(newTableSchema.childTableDbId)
|
||||
: 0,
|
||||
child_table_parent_table_schema_id: newTableSchema.childTableId
|
||||
? numberfy(newTableSchema.childTableId)
|
||||
: 0,
|
||||
table_schema_id: newTableSchema.id
|
||||
? numberfy(newTableSchema.id)
|
||||
: 0,
|
||||
active_data: newTableSchema.updateData ? 1 : 0,
|
||||
};
|
||||
const existingTable = await varDatabaseDbHandler({
|
||||
queryString: `SELECT * FROM ${targetDatabase}.${targetTableName} WHERE db_id = ? AND table_slug = ?`,
|
||||
queryValuesArray: [
|
||||
String(recordedDbEntry.id),
|
||||
String(newTableSchema.tableName),
|
||||
],
|
||||
});
|
||||
const table = existingTable === null || existingTable === void 0 ? void 0 : existingTable[0];
|
||||
if (table === null || table === void 0 ? void 0 : table.id) {
|
||||
tableId = table.id;
|
||||
if (update) {
|
||||
await updateDbEntry({
|
||||
data: newTableEntry,
|
||||
identifierColumnName: "id",
|
||||
identifierValue: table.id,
|
||||
tableName: targetTableName,
|
||||
dbFullName: targetDatabase,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
const newTableEntryRes = await addDbEntry({
|
||||
data: newTableEntry,
|
||||
tableName: targetTableName,
|
||||
dbFullName: targetDatabase,
|
||||
});
|
||||
if ((_a = newTableEntryRes === null || newTableEntryRes === void 0 ? void 0 : newTableEntryRes.payload) === null || _a === void 0 ? void 0 : _a.insertId) {
|
||||
tableId = newTableEntryRes.payload.insertId;
|
||||
}
|
||||
}
|
||||
if (newTableSchema.tableNameOld) {
|
||||
}
|
||||
return tableId;
|
||||
}
|
||||
catch (error) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -1,13 +1,15 @@
|
||||
import { DSQL_TableSchemaType } from "../../types";
|
||||
import { DSQL_FieldSchemaType, DSQL_TableSchemaType } from "../../types";
|
||||
import { DSQL_DATASQUIREL_USER_DATABASES } from "../../types/dsql";
|
||||
type Param = {
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
tableInfoArray: any[];
|
||||
tableInfoArray: DSQL_FieldSchemaType[];
|
||||
tableSchema?: DSQL_TableSchemaType;
|
||||
recordedDbEntry?: any;
|
||||
recordedDbEntry?: DSQL_DATASQUIREL_USER_DATABASES;
|
||||
isMain?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Create Table Functions
|
||||
*/
|
||||
export default function createTable({ dbFullName, tableName, tableInfoArray, tableSchema, recordedDbEntry, }: Param): Promise<any>;
|
||||
export default function createTable({ dbFullName, tableName, tableInfoArray, tableSchema, recordedDbEntry, isMain, }: Param): Promise<number | undefined>;
|
||||
export {};
|
||||
|
||||
+50
-122
@@ -1,127 +1,55 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = createTable;
|
||||
const varDatabaseDbHandler_1 = __importDefault(require("./varDatabaseDbHandler"));
|
||||
const generateColumnDescription_1 = __importDefault(require("./generateColumnDescription"));
|
||||
const supplementTable_1 = __importDefault(require("./supplementTable"));
|
||||
const dbHandler_1 = __importDefault(require("./dbHandler"));
|
||||
import varDatabaseDbHandler from "./varDatabaseDbHandler";
|
||||
import generateColumnDescription from "./generateColumnDescription";
|
||||
import supplementTable from "./supplementTable";
|
||||
import handleTableForeignKey from "./handle-table-foreign-key";
|
||||
import createTableHandleTableRecord from "./create-table-handle-table-record";
|
||||
/**
|
||||
* # Create Table Functions
|
||||
*/
|
||||
function createTable(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, tableName, tableInfoArray, tableSchema, recordedDbEntry, }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
const finalTable = (0, supplementTable_1.default)({ tableInfoArray: tableInfoArray });
|
||||
/**
|
||||
* Grab Schema
|
||||
*
|
||||
* @description Grab Schema
|
||||
*/
|
||||
const createTableQueryArray = [];
|
||||
createTableQueryArray.push(`CREATE TABLE IF NOT EXISTS \`${dbFullName}\`.\`${tableName}\` (`);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
try {
|
||||
if (!recordedDbEntry) {
|
||||
throw new Error("Recorded Db entry not found!");
|
||||
}
|
||||
const existingTable = yield (0, varDatabaseDbHandler_1.default)({
|
||||
queryString: `SELECT * FROM datasquirel.user_database_tables WHERE db_id = ? AND table_slug = ?`,
|
||||
queryValuesArray: [recordedDbEntry.id, tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.tableName],
|
||||
});
|
||||
/** @type {import("../../types").MYSQL_user_database_tables_table_def} */
|
||||
const table = existingTable === null || existingTable === void 0 ? void 0 : existingTable[0];
|
||||
if (!(table === null || table === void 0 ? void 0 : table.id)) {
|
||||
const newTableEntry = yield (0, dbHandler_1.default)({
|
||||
query: `INSERT INTO datasquirel.user_database_tables SET ?`,
|
||||
values: {
|
||||
user_id: recordedDbEntry.user_id,
|
||||
db_id: recordedDbEntry.id,
|
||||
db_slug: recordedDbEntry.db_slug,
|
||||
table_name: tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.tableFullName,
|
||||
table_slug: tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.tableName,
|
||||
child_table: (tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.childTable) ? "1" : null,
|
||||
child_table_parent_database: (tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.childTableDbFullName) || null,
|
||||
child_table_parent_table: (tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.childTableName) || null,
|
||||
date_created: Date(),
|
||||
date_created_code: Date.now(),
|
||||
date_updated: Date(),
|
||||
date_updated_code: Date.now(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (error) { }
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
let primaryKeySet = false;
|
||||
/** @type {import("../../types").DSQL_FieldSchemaType[]} */
|
||||
let foreignKeys = [];
|
||||
////////////////////////////////////////
|
||||
for (let i = 0; i < finalTable.length; i++) {
|
||||
const column = finalTable[i];
|
||||
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, foreignKey, updatedField, onUpdate, onUpdateLiteral, onDelete, onDeleteLiteral, defaultField, encrypted, json, newTempField, notNullValue, originName, plainText, pattern, patternFlags, richText, } = column;
|
||||
if (foreignKey) {
|
||||
foreignKeys.push(Object.assign({}, column));
|
||||
}
|
||||
let { fieldEntryText, newPrimaryKeySet } = (0, generateColumnDescription_1.default)({
|
||||
columnData: column,
|
||||
primaryKeySet: primaryKeySet,
|
||||
});
|
||||
primaryKeySet = newPrimaryKeySet;
|
||||
////////////////////////////////////////
|
||||
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) => {
|
||||
var _a, _b, _c, _d, _e;
|
||||
const fieldName = foreighKey.fieldName;
|
||||
const destinationTableName = (_a = foreighKey.foreignKey) === null || _a === void 0 ? void 0 : _a.destinationTableName;
|
||||
const destinationTableColumnName = (_b = foreighKey.foreignKey) === null || _b === void 0 ? void 0 : _b.destinationTableColumnName;
|
||||
const cascadeDelete = (_c = foreighKey.foreignKey) === null || _c === void 0 ? void 0 : _c.cascadeDelete;
|
||||
const cascadeUpdate = (_d = foreighKey.foreignKey) === null || _d === void 0 ? void 0 : _d.cascadeUpdate;
|
||||
const foreignKeyName = (_e = foreighKey.foreignKey) === null || _e === void 0 ? void 0 : _e.foreignKeyName;
|
||||
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 = yield (0, varDatabaseDbHandler_1.default)({
|
||||
queryString: createTableQuery,
|
||||
});
|
||||
return newTable;
|
||||
export default async function createTable({ dbFullName, tableName, tableInfoArray, tableSchema, recordedDbEntry, isMain, }) {
|
||||
const finalTable = supplementTable({ tableInfoArray: tableInfoArray });
|
||||
let tableId = await createTableHandleTableRecord({
|
||||
recordedDbEntry,
|
||||
tableSchema,
|
||||
isMain,
|
||||
});
|
||||
if (!tableId && !isMain)
|
||||
throw new Error(`Couldn't grab table ID`);
|
||||
const createTableQueryArray = [];
|
||||
createTableQueryArray.push(`CREATE TABLE IF NOT EXISTS \`${dbFullName}\`.\`${tableName}\` (`);
|
||||
let primaryKeySet = false;
|
||||
for (let i = 0; i < finalTable.length; i++) {
|
||||
const column = finalTable[i];
|
||||
let { fieldEntryText, newPrimaryKeySet } = generateColumnDescription({
|
||||
columnData: column,
|
||||
primaryKeySet: primaryKeySet,
|
||||
});
|
||||
primaryKeySet = newPrimaryKeySet;
|
||||
const comma = (() => {
|
||||
if (i === finalTable.length - 1)
|
||||
return "";
|
||||
return ",";
|
||||
})();
|
||||
createTableQueryArray.push(" " + fieldEntryText + 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,
|
||||
});
|
||||
for (let i = 0; i < finalTable.length; i++) {
|
||||
const column = finalTable[i];
|
||||
const { foreignKey, fieldName } = column;
|
||||
if (!fieldName)
|
||||
continue;
|
||||
if (foreignKey) {
|
||||
await handleTableForeignKey({
|
||||
dbFullName,
|
||||
foreignKey,
|
||||
tableName,
|
||||
fieldName,
|
||||
});
|
||||
}
|
||||
}
|
||||
return tableId;
|
||||
}
|
||||
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
type Param = {
|
||||
query: string;
|
||||
values?: string[] | object;
|
||||
};
|
||||
/**
|
||||
* # Main DB Handler Function
|
||||
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||
*/
|
||||
export default function dbHandler({ query, values, }: Param): Promise<any[] | object | null>;
|
||||
export {};
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = dbHandler;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const grab_dsql_connection_1 = __importDefault(require("../../utils/grab-dsql-connection"));
|
||||
/**
|
||||
* # Main DB Handler Function
|
||||
* @requires DSQL_DB_CONN - Gobal Variable for Datasquirel Database
|
||||
*/
|
||||
function dbHandler(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ query, values, }) {
|
||||
var _b;
|
||||
const CONNECTION = (0, grab_dsql_connection_1.default)();
|
||||
let results;
|
||||
try {
|
||||
if (query && values) {
|
||||
results = yield CONNECTION.query(query, values);
|
||||
}
|
||||
else {
|
||||
results = yield CONNECTION.query(query);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `DB Handler Error...`, error);
|
||||
if (process.env.FIRST_RUN) {
|
||||
return null;
|
||||
}
|
||||
console.log("ERROR in dbHandler =>", error.message);
|
||||
console.log(error);
|
||||
console.log(CONNECTION.config());
|
||||
const tmpFolder = path_1.default.resolve(process.cwd(), "./.tmp");
|
||||
if (!fs_1.default.existsSync(tmpFolder))
|
||||
fs_1.default.mkdirSync(tmpFolder, { recursive: true });
|
||||
fs_1.default.appendFileSync(path_1.default.resolve(tmpFolder, "./dbErrorLogs.txt"), JSON.stringify(error, null, 4) + "\n" + Date() + "\n\n\n", "utf8");
|
||||
results = null;
|
||||
}
|
||||
finally {
|
||||
yield (CONNECTION === null || CONNECTION === void 0 ? void 0 : CONNECTION.end());
|
||||
}
|
||||
if (results) {
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
type Param = {
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
};
|
||||
/**
|
||||
* # Drop All Foreign Keys
|
||||
*/
|
||||
export default function dropAllForeignKeys({ dbFullName, tableName, }: Param): Promise<void>;
|
||||
export {};
|
||||
@@ -0,0 +1,35 @@
|
||||
import grabSQLKeyName from "../../utils/grab-sql-key-name";
|
||||
import varDatabaseDbHandler from "./varDatabaseDbHandler";
|
||||
/**
|
||||
* # Drop All Foreign Keys
|
||||
*/
|
||||
export default async function dropAllForeignKeys({ dbFullName, tableName, }) {
|
||||
try {
|
||||
// const rows = await varDatabaseDbHandler({
|
||||
// queryString: `SELECT CONSTRAINT_NAME FROM information_schema.REFERENTIAL_CONSTRAINTS WHERE TABLE_NAME = '${tableName}' AND CONSTRAINT_SCHEMA = '${dbFullName}'`,
|
||||
// });
|
||||
// console.log("rows", rows);
|
||||
// console.log("dbFullName", dbFullName);
|
||||
// console.log("tableName", tableName);
|
||||
// for (const row of rows) {
|
||||
// await varDatabaseDbHandler({
|
||||
// queryString: `ALTER TABLE \`${dbFullName}\`.\`${tableName}\` DROP FOREIGN KEY \`${row.CONSTRAINT_NAME}\`
|
||||
// `,
|
||||
// });
|
||||
// }
|
||||
const foreignKeys = await varDatabaseDbHandler({
|
||||
queryString: `SHOW INDEXES FROM \`${dbFullName}\`.\`${tableName}\` WHERE Key_name LIKE '${grabSQLKeyName({ type: "foreign_key" })}%'`,
|
||||
});
|
||||
for (const fk of foreignKeys) {
|
||||
if (fk.Key_name.match(new RegExp(grabSQLKeyName({ type: "foreign_key" })))) {
|
||||
await varDatabaseDbHandler({
|
||||
queryString: `ALTER TABLE \`${dbFullName}\`.\`${tableName}\` DROP INDEX \`${fk.Key_name}\`
|
||||
`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log(`dropAllForeignKeys ERROR => ${error.message}`);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { DSQL_FieldSchemaType } from "../../types";
|
||||
type Param = {
|
||||
columnData: import("../../types").DSQL_FieldSchemaType;
|
||||
columnData: DSQL_FieldSchemaType;
|
||||
primaryKeySet?: boolean;
|
||||
};
|
||||
type Return = {
|
||||
|
||||
+14
-19
@@ -1,19 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = generateColumnDescription;
|
||||
import dataTypeConstructor from "../../utils/db/schema/data-type-constructor";
|
||||
import dataTypeParser from "../../utils/db/schema/data-type-parser";
|
||||
/**
|
||||
* # Generate Table Column Description
|
||||
*/
|
||||
function generateColumnDescription({ columnData, primaryKeySet, }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
* @description Format tableInfoArray
|
||||
*/
|
||||
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, onUpdateLiteral, notNullValue, } = columnData;
|
||||
export default function generateColumnDescription({ columnData, primaryKeySet, }) {
|
||||
const { fieldName, dataType, nullValue, primaryKey, autoIncrement, defaultValue, defaultValueLiteral, onUpdateLiteral, notNullValue, unique, } = columnData;
|
||||
let fieldEntryText = "";
|
||||
fieldEntryText += `\`${fieldName}\` ${dataType}`;
|
||||
////////////////////////////////////////
|
||||
const finalDataTypeObject = dataTypeParser(dataType);
|
||||
const finalDataType = dataTypeConstructor(finalDataTypeObject.type, finalDataTypeObject.limit, finalDataTypeObject.decimal);
|
||||
fieldEntryText += `\`${fieldName}\` ${finalDataType}`;
|
||||
if (nullValue) {
|
||||
fieldEntryText += " DEFAULT NULL";
|
||||
}
|
||||
@@ -25,29 +20,29 @@ function generateColumnDescription({ columnData, primaryKeySet, }) {
|
||||
fieldEntryText += ` DEFAULT UUID()`;
|
||||
}
|
||||
else {
|
||||
fieldEntryText += ` DEFAULT '${defaultValue}'`;
|
||||
fieldEntryText += ` DEFAULT '${String(defaultValue)
|
||||
.replace(/^\'|\'$/g, "")
|
||||
.replace(/\'/g, "\\'")}'`;
|
||||
}
|
||||
}
|
||||
else if (notNullValue) {
|
||||
fieldEntryText += ` NOT NULL`;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
if (onUpdateLiteral) {
|
||||
fieldEntryText += ` ON UPDATE ${onUpdateLiteral}`;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
if (primaryKey && !primaryKeySet) {
|
||||
fieldEntryText += " PRIMARY KEY";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
if (autoIncrement) {
|
||||
fieldEntryText += " AUTO_INCREMENT";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
if (unique) {
|
||||
fieldEntryText += " UNIQUE";
|
||||
primaryKeySet = true;
|
||||
}
|
||||
return {
|
||||
fieldEntryText,
|
||||
newPrimaryKeySet: primaryKeySet || false,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export default function grabDSQLSchemaIndexComment(): string;
|
||||
@@ -0,0 +1,3 @@
|
||||
export default function grabDSQLSchemaIndexComment() {
|
||||
return `dsql_schema_index`;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { DSQL_ForeignKeyType } from "../../types";
|
||||
type Param = {
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
foreignKey: DSQL_ForeignKeyType;
|
||||
fieldName: string;
|
||||
errorLogs?: any[];
|
||||
};
|
||||
/**
|
||||
* # Update table function
|
||||
*/
|
||||
export default function handleTableForeignKey({ dbFullName, tableName, foreignKey, errorLogs, fieldName, }: Param): Promise<void>;
|
||||
export {};
|
||||
@@ -0,0 +1,24 @@
|
||||
import varDatabaseDbHandler from "./varDatabaseDbHandler";
|
||||
/**
|
||||
* # Update table function
|
||||
*/
|
||||
export default async function handleTableForeignKey({ dbFullName, tableName, foreignKey, errorLogs, fieldName, }) {
|
||||
const { destinationTableName, destinationTableColumnName, cascadeDelete, cascadeUpdate, foreignKeyName, } = foreignKey;
|
||||
let finalQueryString = `ALTER TABLE \`${dbFullName}\`.\`${tableName}\``;
|
||||
finalQueryString += ` ADD CONSTRAINT \`${foreignKeyName}\` FOREIGN KEY (\`${fieldName}\`)`;
|
||||
finalQueryString += ` REFERENCES \`${destinationTableName}\`(\`${destinationTableColumnName}\`)`;
|
||||
if (cascadeDelete)
|
||||
finalQueryString += ` ON DELETE CASCADE`;
|
||||
if (cascadeUpdate)
|
||||
finalQueryString += ` ON UPDATE CASCADE`;
|
||||
// let foreinKeyText = `ADD CONSTRAINT \`${foreignKeyName}\` FOREIGN KEY (\`${destinationTableColumnType}\`) REFERENCES \`${destinationTableName}\`(\`${destinationTableColumnName}\`)${
|
||||
// cascadeDelete ? " ON DELETE CASCADE" : ""
|
||||
// }${cascadeUpdate ? " ON UPDATE CASCADE" : ""}`;
|
||||
// let finalQueryString = `ALTER TABLE \`${dbFullName}\`.\`${tableName}\` ${foreinKeyText}`;
|
||||
const addForeignKey = await varDatabaseDbHandler({
|
||||
queryString: finalQueryString,
|
||||
});
|
||||
if (!(addForeignKey === null || addForeignKey === void 0 ? void 0 : addForeignKey.serverStatus)) {
|
||||
errorLogs === null || errorLogs === void 0 ? void 0 : errorLogs.push(addForeignKey);
|
||||
}
|
||||
}
|
||||
+16
-33
@@ -1,34 +1,17 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = noDatabaseDbHandler;
|
||||
const dbHandler_1 = __importDefault(require("./dbHandler"));
|
||||
function noDatabaseDbHandler(queryString) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
let results;
|
||||
try {
|
||||
results = yield (0, dbHandler_1.default)({ query: queryString });
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `No DB Handler Error`, error);
|
||||
}
|
||||
if (results) {
|
||||
return results;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
import dbHandler from "../../functions/backend/dbHandler";
|
||||
export default async function noDatabaseDbHandler(queryString) {
|
||||
var _a;
|
||||
let results;
|
||||
try {
|
||||
results = await dbHandler({ query: queryString });
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `No DB Handler Error`, error);
|
||||
}
|
||||
if (results) {
|
||||
return results;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -1,10 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = slugToCamelTitle;
|
||||
/**
|
||||
* # Sulg To Camel Case
|
||||
*/
|
||||
function slugToCamelTitle(text) {
|
||||
export default function slugToCamelTitle(text) {
|
||||
if (text) {
|
||||
let addArray = text.split("-").filter((item) => item !== "");
|
||||
let camelArray = addArray.map((item) => {
|
||||
|
||||
+1
-4
@@ -1,10 +1,7 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = supplementTable;
|
||||
/**
|
||||
* # Supplement Table
|
||||
*/
|
||||
function supplementTable({ tableInfoArray }) {
|
||||
export default function supplementTable({ tableInfoArray }) {
|
||||
/**
|
||||
* Format tableInfoArray
|
||||
*
|
||||
|
||||
+9
-9
@@ -1,19 +1,19 @@
|
||||
import { DSQL_DatabaseSchemaType, DSQL_FieldSchemaType, DSQL_IndexSchemaType, DSQL_TableSchemaType } from "../../types";
|
||||
import { DSQL_DATASQUIREL_USER_DATABASES } from "../../types/dsql";
|
||||
type Param = {
|
||||
dbFullName: string;
|
||||
tableName: string;
|
||||
tableSchema: import("../../types").DSQL_TableSchemaType;
|
||||
tableNameFull?: string;
|
||||
tableInfoArray: import("../../types").DSQL_FieldSchemaType[];
|
||||
tableSchema: DSQL_TableSchemaType;
|
||||
tableFields: DSQL_FieldSchemaType[];
|
||||
userId?: number | string | null;
|
||||
dbSchema: import("../../types").DSQL_DatabaseSchemaType[];
|
||||
tableIndexes?: import("../../types").DSQL_IndexSchemaType[];
|
||||
dbSchema: DSQL_DatabaseSchemaType;
|
||||
tableIndexes?: DSQL_IndexSchemaType[];
|
||||
clone?: boolean;
|
||||
tableIndex?: number;
|
||||
childDb?: boolean;
|
||||
recordedDbEntry?: any;
|
||||
recordedDbEntry?: DSQL_DATASQUIREL_USER_DATABASES;
|
||||
isMain?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Update table function
|
||||
*/
|
||||
export default function updateTable({ dbFullName, tableName, tableInfoArray, userId, dbSchema, tableIndexes, tableSchema, clone, childDb, tableIndex, tableNameFull, recordedDbEntry, }: Param): Promise<any>;
|
||||
export default function updateTable({ dbFullName, tableName, tableFields, userId, dbSchema, tableIndexes, tableSchema, clone, recordedDbEntry, isMain, }: Param): Promise<number | undefined>;
|
||||
export {};
|
||||
|
||||
+290
-378
File diff suppressed because it is too large
Load Diff
+39
-56
@@ -1,62 +1,45 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = varDatabaseDbHandler;
|
||||
const dbHandler_1 = __importDefault(require("./dbHandler"));
|
||||
import dbHandler from "../../functions/backend/dbHandler";
|
||||
/**
|
||||
* # DB handler for specific database
|
||||
*/
|
||||
function varDatabaseDbHandler(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ queryString, queryValuesArray, }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
if (queryString &&
|
||||
queryValuesArray &&
|
||||
Array.isArray(queryValuesArray) &&
|
||||
queryValuesArray[0]) {
|
||||
results = yield (0, dbHandler_1.default)({
|
||||
query: queryString,
|
||||
values: queryValuesArray,
|
||||
});
|
||||
}
|
||||
else {
|
||||
results = yield (0, dbHandler_1.default)({
|
||||
query: queryString,
|
||||
});
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
export default async function varDatabaseDbHandler({ queryString, queryValuesArray, }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
if (queryString &&
|
||||
queryValuesArray &&
|
||||
Array.isArray(queryValuesArray) &&
|
||||
queryValuesArray[0]) {
|
||||
results = await dbHandler({
|
||||
query: queryString,
|
||||
values: queryValuesArray,
|
||||
});
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
console.log("Shell Vardb Error =>", error.message);
|
||||
else {
|
||||
results = await dbHandler({
|
||||
query: queryString,
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
return results;
|
||||
});
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
console.log("Shell Vardb Error =>", error.message);
|
||||
}
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
return results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user