mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 01:46:02 +00:00
29 lines
572 B
JavaScript
29 lines
572 B
JavaScript
export default class ScriptWriter {
|
|
constructor() {
|
|
this.s = '';
|
|
this.varCount = 0;
|
|
}
|
|
|
|
allocVariable(prefix = 'var') {
|
|
this.varCount += 1;
|
|
return `${prefix}${this.varCount}`;
|
|
}
|
|
|
|
put(s = '') {
|
|
this.s += s;
|
|
this.s += '\n';
|
|
}
|
|
|
|
assign(variableName, functionName, props) {
|
|
this.put(`const ${variableName} = await dbgateApi.${functionName}(${JSON.stringify(props)});`);
|
|
}
|
|
|
|
copyStream(sourceVar, targetVar) {
|
|
this.put(`await dbgateApi.copyStream(${sourceVar}, ${targetVar});`);
|
|
}
|
|
|
|
comment(s) {
|
|
this.put(`// ${s}`);
|
|
}
|
|
}
|