Commit 0bddf01a authored by xiegelin's avatar xiegelin

pgsql 优化

parent bec3f283
...@@ -111,12 +111,22 @@ async function main() { ...@@ -111,12 +111,22 @@ async function main() {
const result = await client.query(sql, ['public', processedTableName]); const result = await client.query(sql, ['public', processedTableName]);
const rows = result.rows; const rows = result.rows;
// Get table comment via pg_catalog
const tableCommentResult = await client.query(
`SELECT obj_description(c.oid) AS table_comment
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = 'public' AND c.relname = $1`,
[processedTableName]
);
const tableComment = tableCommentResult.rows[0]?.table_comment || '';
if (rows.length === 0) { if (rows.length === 0) {
console.error( console.error(
`***** No results found for table ${processedTableName}. *****` `***** No results found for table ${processedTableName}. *****`
); );
} else { } else {
generateXMLWithTableColumns(processedTableName, rows); generateXMLWithTableColumns(processedTableName, rows, tableComment);
console.log( console.log(
`===== XML file generated successfully for ${processedTableName}! =====` `===== XML file generated successfully for ${processedTableName}! =====`
); );
...@@ -133,14 +143,15 @@ async function main() { ...@@ -133,14 +143,15 @@ async function main() {
} }
} }
function generateXMLWithTableColumns(tableName, rows) { function generateXMLWithTableColumns(tableName, rows, tableComment) {
const label = tableComment ? `${tableName} 
${tableComment}` : tableName;
// XML template start with the table name in the label // XML template start with the table name in the label
let xmlContent = `<mxGraphModel> let xmlContent = `<mxGraphModel>
<root> <root>
<mxCell id="0"/> <mxCell id="0"/>
<mxCell id="1" parent="0"/> <mxCell id="1" parent="0"/>
<object label="${tableName}" id="2"> <object label="${label}" id="2">
<mxCell style="swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=30;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1"> <mxCell style="swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=40;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<mxGeometry x="340" y="140" width="260" height="${ <mxGeometry x="340" y="140" width="260" height="${
30 + rows.length * 30 30 + rows.length * 30
}" as="geometry"/> }" as="geometry"/>
...@@ -183,7 +194,11 @@ function generateXMLWithTableColumns(tableName, rows) { ...@@ -183,7 +194,11 @@ function generateXMLWithTableColumns(tableName, rows) {
</root> </root>
</mxGraphModel>`; </mxGraphModel>`;
// console.log(xmlContent); // console.log(xmlContent);
fs.writeFileSync(`tableStructureXml/${tableName}.xml`, xmlContent); const filePath = `tableStructureXml/${tableName}.xml`;
if (fs.existsSync(filePath)) {
console.log(`[覆盖] ${filePath} 已存在,已覆盖。`);
}
fs.writeFileSync(filePath, xmlContent);
} }
main(); main();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment