Updates
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user