mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 14:06:00 +00:00
SYNC: Merge pull request #3 from dbgate/feature/zip
This commit is contained in:
@@ -54,8 +54,8 @@ export class ScriptWriter {
|
||||
this._put(`await dbgateApi.importDatabase(${JSON.stringify(options)});`);
|
||||
}
|
||||
|
||||
dataDuplicator(options) {
|
||||
this._put(`await dbgateApi.dataDuplicator(${JSON.stringify(options, null, 2)});`);
|
||||
dataReplicator(options) {
|
||||
this._put(`await dbgateApi.dataReplicator(${JSON.stringify(options, null, 2)});`);
|
||||
}
|
||||
|
||||
comment(s) {
|
||||
@@ -72,6 +72,10 @@ export class ScriptWriter {
|
||||
|
||||
return prefix + this.s;
|
||||
}
|
||||
|
||||
zipDirectory(inputDirectory, outputFile) {
|
||||
this._put(`await dbgateApi.zipDirectory('${inputDirectory}', '${outputFile}');`);
|
||||
}
|
||||
}
|
||||
|
||||
export class ScriptWriterJson {
|
||||
@@ -138,13 +142,21 @@ export class ScriptWriterJson {
|
||||
});
|
||||
}
|
||||
|
||||
dataDuplicator(options) {
|
||||
dataReplicator(options) {
|
||||
this.commands.push({
|
||||
type: 'dataDuplicator',
|
||||
type: 'dataReplicator',
|
||||
options,
|
||||
});
|
||||
}
|
||||
|
||||
zipDirectory(inputDirectory, outputFile) {
|
||||
this.commands.push({
|
||||
type: 'zipDirectory',
|
||||
inputDirectory,
|
||||
outputFile,
|
||||
});
|
||||
}
|
||||
|
||||
getScript(schedule = null) {
|
||||
return {
|
||||
type: 'json',
|
||||
@@ -185,8 +197,11 @@ export function jsonScriptToJavascript(json) {
|
||||
case 'importDatabase':
|
||||
script.importDatabase(cmd.options);
|
||||
break;
|
||||
case 'dataDuplicator':
|
||||
script.dataDuplicator(cmd.options);
|
||||
case 'dataReplicator':
|
||||
script.dataReplicator(cmd.options);
|
||||
break;
|
||||
case 'zipDirectory':
|
||||
script.zipDirectory(cmd.inputDirectory, cmd.outputFile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,9 @@ export function createBulkInsertStreamBase(driver: EngineDriver, stream, dbhan,
|
||||
dmp.putRaw(';');
|
||||
// require('fs').writeFileSync('/home/jena/test.sql', dmp.s);
|
||||
// console.log(dmp.s);
|
||||
await driver.query(dbhan, dmp.s, { discardResult: true });
|
||||
if (rows.length > 0) {
|
||||
await driver.query(dbhan, dmp.s, { discardResult: true });
|
||||
}
|
||||
writable.rowsReporter.add(rows.length);
|
||||
} else {
|
||||
for (const row of rows) {
|
||||
|
||||
@@ -549,3 +549,20 @@ export function pinoLogRecordToMessageRecord(logRecord, defaultSeverity = 'info'
|
||||
severity: levelToSeverity[level] ?? defaultSeverity,
|
||||
};
|
||||
}
|
||||
|
||||
export function jsonLinesStringify(jsonArray: any[]): string {
|
||||
return jsonArray.map(json => JSON.stringify(json)).join('\n');
|
||||
}
|
||||
export function jsonLinesParse(jsonLines: string): any[] {
|
||||
return jsonLines
|
||||
.split('\n')
|
||||
.filter(x => x.trim())
|
||||
.map(line => {
|
||||
try {
|
||||
return JSON.parse(line);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.filter(x => x);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user