This commit is contained in:
2026-01-14 11:01:08 +01:00
parent 0a03405598
commit b50e100732
8 changed files with 91 additions and 20 deletions
@@ -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 };
}
+22
View File
@@ -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,