generate shell script

This commit is contained in:
Jan Prochazka
2020-06-06 21:48:29 +02:00
parent f03a8c258a
commit 74aa90fd2a
12 changed files with 430 additions and 32 deletions

View 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});`);
}
}