mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 08:45:59 +00:00
generate shell script
This commit is contained in:
26
packages/web/src/impexp/ScriptWriter.js
Normal file
26
packages/web/src/impexp/ScriptWriter.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export default class ScriptWriter {
|
||||
constructor() {
|
||||
this.s = '';
|
||||
this.put('const dbgateApi = require("@dbgate/api");');
|
||||
this.put('async function run() {');
|
||||
}
|
||||
|
||||
put(s) {
|
||||
this.s += s;
|
||||
this.s += '\n';
|
||||
}
|
||||
|
||||
finish() {
|
||||
this.put('await dbgateApi.copyStream(queryReader, csvWriter);');
|
||||
this.put('dbgateApi.runScript(run);');
|
||||
this.put('}');
|
||||
}
|
||||
|
||||
assign(variableName, functionName, props) {
|
||||
this.put(`const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
|
||||
}
|
||||
|
||||
copyStream(sourceVar, targetVar) {
|
||||
this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user