Updates
This commit is contained in:
parent
0a03405598
commit
b50e100732
@ -29,14 +29,25 @@ function dbSchemaToType(params) {
|
||||
});
|
||||
const defDbName = (_b = (datasquirelSchema.dbName ||
|
||||
((_a = datasquirelSchema.dbFullName) === null || _a === void 0 ? void 0 : _a.replace(new RegExp(`${app_names_1.AppNames["DsqlDbPrefix"]}\\d+_`), "")))) === null || _b === void 0 ? void 0 : _b.toUpperCase().replace(/ /g, "_");
|
||||
const defNames = [];
|
||||
const schemas = dbTablesSchemas
|
||||
.map((table) => (0, generate_type_definitions_1.default)({
|
||||
paradigm: "TypeScript",
|
||||
table,
|
||||
typeDefName: `DSQL_${defDbName}_${table.tableName.toUpperCase()}`,
|
||||
allValuesOptional: true,
|
||||
addExport: true,
|
||||
}))
|
||||
.map((table) => {
|
||||
var _a;
|
||||
const defObj = (0, generate_type_definitions_1.default)({
|
||||
paradigm: "TypeScript",
|
||||
table,
|
||||
typeDefName: `DSQL_${defDbName}_${table.tableName.toUpperCase()}`,
|
||||
allValuesOptional: true,
|
||||
addExport: true,
|
||||
});
|
||||
if ((_a = defObj.tdName) === null || _a === void 0 ? void 0 : _a.match(/./)) {
|
||||
defNames.push(defObj.tdName);
|
||||
}
|
||||
return defObj.typeDefinition;
|
||||
})
|
||||
.filter((schm) => typeof schm == "string");
|
||||
return [tableNames, ...schemas];
|
||||
const allTd = (defNames === null || defNames === void 0 ? void 0 : defNames[0])
|
||||
? `export type DSQL_${defDbName}_ALL_TYPEDEFS = ${defNames.join(` & `)}`
|
||||
: ``;
|
||||
return [tableNames, ...schemas, allTd];
|
||||
}
|
||||
|
||||
@ -8,5 +8,8 @@ type Param = {
|
||||
addExport?: boolean;
|
||||
dbName?: string;
|
||||
};
|
||||
export default function generateTypeDefinition({ paradigm, table, query, typeDefName, allValuesOptional, addExport, dbName, }: Param): string | null;
|
||||
export default function generateTypeDefinition({ paradigm, table, query, typeDefName, allValuesOptional, addExport, dbName, }: Param): {
|
||||
typeDefinition: string | null;
|
||||
tdName: string;
|
||||
};
|
||||
export {};
|
||||
|
||||
@ -7,8 +7,9 @@ exports.default = generateTypeDefinition;
|
||||
const default_fields_regexp_1 = __importDefault(require("./default-fields-regexp"));
|
||||
function generateTypeDefinition({ paradigm, table, query, typeDefName, allValuesOptional, addExport, dbName, }) {
|
||||
let typeDefinition = ``;
|
||||
let tdName = ``;
|
||||
try {
|
||||
const tdName = typeDefName
|
||||
tdName = typeDefName
|
||||
? typeDefName
|
||||
: dbName
|
||||
? `DSQL_${dbName}_${table.tableName}`.toUpperCase()
|
||||
@ -67,5 +68,5 @@ function generateTypeDefinition({ paradigm, table, query, typeDefName, allValues
|
||||
console.log(error.message);
|
||||
typeDefinition = null;
|
||||
}
|
||||
return typeDefinition;
|
||||
return { typeDefinition, tdName };
|
||||
}
|
||||
|
||||
21
dist/package-shared/shell/utils/updateTable.js
vendored
21
dist/package-shared/shell/utils/updateTable.js
vendored
@ -19,6 +19,7 @@ const handle_table_foreign_key_1 = __importDefault(require("./handle-table-forei
|
||||
const handle_dsql_schema_fields_1 = __importDefault(require("./handle-dsql-schema-fields"));
|
||||
const handle_mariadb_existing_columns_1 = __importDefault(require("./handle-mariadb-existing-columns"));
|
||||
const update_table_init_1 = __importDefault(require("./update-table-init"));
|
||||
const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||
/**
|
||||
* # Update table function
|
||||
*/
|
||||
@ -41,6 +42,10 @@ function updateTable(_a) {
|
||||
* @description Try to undate table, catch error if anything goes wrong
|
||||
*/
|
||||
try {
|
||||
(0, debug_log_1.default)({
|
||||
log: `Handling Existing Columns ...`,
|
||||
addTime: true,
|
||||
});
|
||||
const { allExistingColumns, upToDateTableFieldsArray } = yield (0, handle_mariadb_existing_columns_1.default)({
|
||||
dbFullName,
|
||||
dbSchema,
|
||||
@ -54,6 +59,10 @@ function updateTable(_a) {
|
||||
* @description Iterate through each field object and
|
||||
* perform operations
|
||||
*/
|
||||
(0, debug_log_1.default)({
|
||||
log: `Handling Schema Fields ...`,
|
||||
addTime: true,
|
||||
});
|
||||
yield (0, handle_dsql_schema_fields_1.default)({
|
||||
dbFullName,
|
||||
tableName,
|
||||
@ -66,6 +75,10 @@ function updateTable(_a) {
|
||||
* @description Iterate through each datasquirel schema
|
||||
* table index(if available), and perform operations
|
||||
*/
|
||||
(0, debug_log_1.default)({
|
||||
log: `Handling Table Foreign Keys ...`,
|
||||
addTime: true,
|
||||
});
|
||||
yield (0, handle_table_foreign_key_1.default)({
|
||||
dbFullName,
|
||||
fields: upToDateTableFieldsArray,
|
||||
@ -78,6 +91,10 @@ function updateTable(_a) {
|
||||
* @description Iterate through each datasquirel schema
|
||||
* table index(if available), and perform operations
|
||||
*/
|
||||
(0, debug_log_1.default)({
|
||||
log: `Handling Table Indexes ...`,
|
||||
addTime: true,
|
||||
});
|
||||
if (tableIndexes === null || tableIndexes === void 0 ? void 0 : tableIndexes[0]) {
|
||||
(0, handle_indexes_1.default)({
|
||||
dbFullName,
|
||||
@ -91,6 +108,10 @@ function updateTable(_a) {
|
||||
* @description Iterate through each datasquirel schema
|
||||
* table unique constraint(if available), and perform operations
|
||||
*/
|
||||
(0, debug_log_1.default)({
|
||||
log: `Handling Unique Constraints ...`,
|
||||
addTime: true,
|
||||
});
|
||||
if (tableUniqueConstraints === null || tableUniqueConstraints === void 0 ? void 0 : tableUniqueConstraints[0]) {
|
||||
(0, handle_unique_constraints_1.default)({
|
||||
dbFullName,
|
||||
|
||||
@ -42,17 +42,29 @@ export default function dbSchemaToType(params?: Params): string[] | undefined {
|
||||
?.toUpperCase()
|
||||
.replace(/ /g, "_");
|
||||
|
||||
const defNames: string[] = [];
|
||||
|
||||
const schemas = dbTablesSchemas
|
||||
.map((table) =>
|
||||
generateTypeDefinition({
|
||||
.map((table) => {
|
||||
const defObj = generateTypeDefinition({
|
||||
paradigm: "TypeScript",
|
||||
table,
|
||||
typeDefName: `DSQL_${defDbName}_${table.tableName.toUpperCase()}`,
|
||||
allValuesOptional: true,
|
||||
addExport: true,
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
if (defObj.tdName?.match(/./)) {
|
||||
defNames.push(defObj.tdName);
|
||||
}
|
||||
|
||||
return defObj.typeDefinition;
|
||||
})
|
||||
.filter((schm) => typeof schm == "string");
|
||||
|
||||
return [tableNames, ...schemas];
|
||||
const allTd = defNames?.[0]
|
||||
? `export type DSQL_${defDbName}_ALL_TYPEDEFS = ${defNames.join(` & `)}`
|
||||
: ``;
|
||||
|
||||
return [tableNames, ...schemas, allTd];
|
||||
}
|
||||
|
||||
@ -19,11 +19,12 @@ export default function generateTypeDefinition({
|
||||
allValuesOptional,
|
||||
addExport,
|
||||
dbName,
|
||||
}: Param): string | null {
|
||||
}: Param) {
|
||||
let typeDefinition: string | null = ``;
|
||||
let tdName: string | null = ``;
|
||||
|
||||
try {
|
||||
const tdName = typeDefName
|
||||
tdName = typeDefName
|
||||
? typeDefName
|
||||
: dbName
|
||||
? `DSQL_${dbName}_${table.tableName}`.toUpperCase()
|
||||
@ -101,5 +102,5 @@ export default function generateTypeDefinition({
|
||||
typeDefinition = null;
|
||||
}
|
||||
|
||||
return typeDefinition;
|
||||
return { typeDefinition, tdName };
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import handleTableForeignKey from "./handle-table-foreign-key";
|
||||
import handleDSQLSchemaFields from "./handle-dsql-schema-fields";
|
||||
import handleMariaDBExistingColumns from "./handle-mariadb-existing-columns";
|
||||
import updateTableInit from "./update-table-init";
|
||||
import debugLog from "../../utils/logging/debug-log";
|
||||
|
||||
type Param = {
|
||||
dbFullName: string;
|
||||
@ -62,6 +63,11 @@ export default async function updateTable({
|
||||
* @description Try to undate table, catch error if anything goes wrong
|
||||
*/
|
||||
try {
|
||||
debugLog({
|
||||
log: `Handling Existing Columns ...`,
|
||||
addTime: true,
|
||||
});
|
||||
|
||||
const { allExistingColumns, upToDateTableFieldsArray } =
|
||||
await handleMariaDBExistingColumns({
|
||||
dbFullName,
|
||||
@ -77,6 +83,10 @@ export default async function updateTable({
|
||||
* @description Iterate through each field object and
|
||||
* perform operations
|
||||
*/
|
||||
debugLog({
|
||||
log: `Handling Schema Fields ...`,
|
||||
addTime: true,
|
||||
});
|
||||
await handleDSQLSchemaFields({
|
||||
dbFullName,
|
||||
tableName,
|
||||
@ -90,6 +100,10 @@ export default async function updateTable({
|
||||
* @description Iterate through each datasquirel schema
|
||||
* table index(if available), and perform operations
|
||||
*/
|
||||
debugLog({
|
||||
log: `Handling Table Foreign Keys ...`,
|
||||
addTime: true,
|
||||
});
|
||||
await handleTableForeignKey({
|
||||
dbFullName,
|
||||
fields: upToDateTableFieldsArray,
|
||||
@ -103,6 +117,10 @@ export default async function updateTable({
|
||||
* @description Iterate through each datasquirel schema
|
||||
* table index(if available), and perform operations
|
||||
*/
|
||||
debugLog({
|
||||
log: `Handling Table Indexes ...`,
|
||||
addTime: true,
|
||||
});
|
||||
if (tableIndexes?.[0]) {
|
||||
handleIndexescreateDbFromSchema({
|
||||
dbFullName,
|
||||
@ -117,6 +135,10 @@ export default async function updateTable({
|
||||
* @description Iterate through each datasquirel schema
|
||||
* table unique constraint(if available), and perform operations
|
||||
*/
|
||||
debugLog({
|
||||
log: `Handling Unique Constraints ...`,
|
||||
addTime: true,
|
||||
});
|
||||
if (tableUniqueConstraints?.[0]) {
|
||||
handleUniqueConstraintsCreateDbFromSchema({
|
||||
dbFullName,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/datasquirel",
|
||||
"version": "5.7.27",
|
||||
"version": "5.7.28",
|
||||
"description": "Cloud-based SQL data management tool",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user