Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
drawio_utils
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
解戈麟
drawio_utils
Commits
0bddf01a
Commit
0bddf01a
authored
Apr 29, 2026
by
xiegelin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pgsql 优化
parent
bec3f283
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
5 deletions
+20
-5
postgreSQL.js
postgreSQL.js
+20
-5
No files found.
postgreSQL.js
View file @
0bddf01a
...
...
@@ -111,12 +111,22 @@ async function main() {
const
result
=
await
client
.
query
(
sql
,
[
'
public
'
,
processedTableName
]);
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
)
{
console
.
error
(
`***** No results found for table
${
processedTableName
}
. *****`
);
}
else
{
generateXMLWithTableColumns
(
processedTableName
,
rows
);
generateXMLWithTableColumns
(
processedTableName
,
rows
,
tableComment
);
console
.
log
(
`===== XML file generated successfully for
${
processedTableName
}
! =====`
);
...
...
@@ -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
let
xmlContent
=
`<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<object label="
${
tableName
}
" id="2">
<mxCell style="swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=
3
0;horizontalStack=0;resizeParent=1;resizeParentMax=0;resizeLast=0;collapsible=1;marginBottom=0;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="1">
<object label="
${
label
}
" id="2">
<mxCell style="swimlane;fontStyle=1;childLayout=stackLayout;horizontal=1;startSize=
4
0;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="
${
30
+
rows
.
length
*
30
}
" as="geometry"/>
...
...
@@ -183,7 +194,11 @@ function generateXMLWithTableColumns(tableName, rows) {
</root>
</mxGraphModel>`
;
// 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
();
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment