From f8da3c3476ec7b33bb0b79baded34c07f44c6e7d Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 17 Feb 2022 17:06:28 +0100 Subject: [PATCH] xml quick export --- plugins/dbgate-plugin-xml/src/backend/writer.js | 8 +++++--- plugins/dbgate-plugin-xml/src/frontend/index.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/plugins/dbgate-plugin-xml/src/backend/writer.js b/plugins/dbgate-plugin-xml/src/backend/writer.js index a881a1a3..e5abab25 100644 --- a/plugins/dbgate-plugin-xml/src/backend/writer.js +++ b/plugins/dbgate-plugin-xml/src/backend/writer.js @@ -21,16 +21,17 @@ function escapeXml(value) { class StringifyStream extends stream.Transform { constructor({ itemElementName, rootElementName }) { super({ objectMode: true }); - this.itemElementName = itemElementName; - this.rootElementName = rootElementName; + this.itemElementName = itemElementName || 'row'; + this.rootElementName = rootElementName || 'root'; this.startElement(this.rootElementName); + this.push('\n'); } startElement(element) { this.push('<'); this.push(element); - this.push('>\n'); + this.push('>'); } endElement(element) { @@ -47,6 +48,7 @@ class StringifyStream extends stream.Transform { _transform(chunk, encoding, done) { this.startElement(this.itemElementName); + this.push('\n'); for (const key of Object.keys(chunk)) { this.elementValue(key, chunk[key]); } diff --git a/plugins/dbgate-plugin-xml/src/frontend/index.js b/plugins/dbgate-plugin-xml/src/frontend/index.js index 930d2ed3..ebca5782 100644 --- a/plugins/dbgate-plugin-xml/src/frontend/index.js +++ b/plugins/dbgate-plugin-xml/src/frontend/index.js @@ -30,5 +30,19 @@ const fileFormat = { export default { fileFormats: [fileFormat], + + quickExports: [ + { + label: 'XML file', + extension: 'xml', + createWriter: (fileName) => ({ + functionName: 'writer@dbgate-plugin-xml', + props: { + fileName, + }, + }), + }, + ], + }; \ No newline at end of file