generate script fixes

This commit is contained in:
Jan Prochazka
2020-06-06 22:17:17 +02:00
parent 74aa90fd2a
commit 617548cd50
6 changed files with 40 additions and 28 deletions

View File

@@ -2,25 +2,26 @@ export default class ScriptWriter {
constructor() {
this.s = '';
this.put('const dbgateApi = require("@dbgate/api");');
this.put();
this.put('async function run() {');
}
put(s) {
put(s = '') {
this.s += s;
this.s += '\n';
}
finish() {
this.put('await dbgateApi.copyStream(queryReader, csvWriter);');
this.put('dbgateApi.runScript(run);');
this.put('}');
this.put();
this.put('dbgateApi.runScript(run);');
}
assign(variableName, functionName, props) {
this.put(`const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
this.put(` const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
}
copyStream(sourceVar, targetVar) {
this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
this.put(` await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
}
}