mirror of https://github.com/Fabio286/antares.git
feat: export database as zip sql file
This commit is contained in:
parent
db628f7722
commit
8f3efabb69
|
@ -1,4 +1,5 @@
|
|||
import fs from 'fs';
|
||||
import { createGzip } from 'zlib';
|
||||
import path from 'path';
|
||||
import EventEmitter from 'events';
|
||||
|
||||
|
@ -8,12 +9,19 @@ export class BaseExporter extends EventEmitter {
|
|||
this._tables = tables;
|
||||
this._options = options;
|
||||
this._isCancelled = false;
|
||||
this._outputStream = fs.createWriteStream(this._options.outputFile, {
|
||||
flags: 'w'
|
||||
});
|
||||
this._outputFileStream = fs.createWriteStream(this._options.outputFile, { flags: 'w' });
|
||||
this._processedStream = null;
|
||||
this._state = {};
|
||||
|
||||
this._outputStream.once('error', err => {
|
||||
if (this._options.outputFormat === 'sql.zip') {
|
||||
const outputZipStream = createGzip();
|
||||
outputZipStream.pipe(this._outputFileStream);
|
||||
this._processedStream = outputZipStream;
|
||||
}
|
||||
else
|
||||
this._processedStream = this._outputFileStream;
|
||||
|
||||
this._processedStream.once('error', err => {
|
||||
this._isCancelled = true;
|
||||
this.emit('error', err);
|
||||
});
|
||||
|
@ -29,7 +37,7 @@ export class BaseExporter extends EventEmitter {
|
|||
throw err;
|
||||
}
|
||||
finally {
|
||||
this._outputStream.end();
|
||||
this._processedStream.end();
|
||||
this.emit('end');
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +76,7 @@ export class BaseExporter extends EventEmitter {
|
|||
const fileName = path.basename(this._options.outputFile);
|
||||
this.emit('error', `The file ${fileName} is not accessible`);
|
||||
}
|
||||
this._outputStream.write(data);
|
||||
this._processedStream.write(data);
|
||||
}
|
||||
|
||||
dump () {
|
||||
|
|
|
@ -181,11 +181,10 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="column col-4">
|
||||
<h4>
|
||||
<h5 class="h5">
|
||||
{{ $t('word.options') }}
|
||||
</h4>
|
||||
<span>{{ $t('word.includes') }}:</span>
|
||||
|
||||
</h5>
|
||||
<span class="h6">{{ $t('word.includes') }}:</span>
|
||||
<label
|
||||
v-for="(_, key) in options.includes"
|
||||
:key="key"
|
||||
|
@ -194,7 +193,7 @@
|
|||
<input v-model="options.includes[key]" type="checkbox"><i class="form-icon" /> {{ $t(`word.${key}`) }}
|
||||
</label>
|
||||
|
||||
<div class="mt-4 mb-2">
|
||||
<div class="h6 mt-4 mb-2">
|
||||
{{ $t('message.newInserStmtEvery') }}:
|
||||
</div>
|
||||
<div class="columns">
|
||||
|
@ -217,6 +216,22 @@
|
|||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="h6 mb-2 mt-4">
|
||||
{{ $t('message.ourputFormat') }}:
|
||||
</div>
|
||||
<div class="columns">
|
||||
<div class="column h5 mb-4">
|
||||
<select v-model="options.outputFormat" class="form-select">
|
||||
<option value="sql">
|
||||
{{ $t('message.singleFile', {ext: '.sql'}) }}
|
||||
</option>
|
||||
<option value="sql.zip">
|
||||
{{ $t('message.zipCompressedFile', {ext: '.sql'}) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -275,6 +290,7 @@ export default {
|
|||
tables: [],
|
||||
options: {
|
||||
includes: {},
|
||||
outputFormat: 'sql',
|
||||
sqlInsertAfter: 250,
|
||||
sqlInsertDivider: 'bytes'
|
||||
},
|
||||
|
@ -299,7 +315,7 @@ export default {
|
|||
},
|
||||
filename () {
|
||||
const date = moment().format('YYYY-MM-DD');
|
||||
return `${this.selectedSchema}_${date}.sql`;
|
||||
return `${this.selectedSchema}_${date}.${this.options.outputFormat}`;
|
||||
},
|
||||
dumpFilePath () {
|
||||
return `${this.basePath}/${this.filename}`;
|
||||
|
|
|
@ -283,7 +283,10 @@ module.exports = {
|
|||
manualCommit: 'Manual commit',
|
||||
actionSuccessful: '{action} successful',
|
||||
importQueryErrors: 'Warning: {n} error has accurrend | Warning: {n} errors occurred',
|
||||
executedQueries: '{n} query executed | {n} queries executed'
|
||||
executedQueries: '{n} query executed | {n} queries executed',
|
||||
ourputFormat: 'Output format',
|
||||
singleFile: 'Single {ext} file',
|
||||
zipCompressedFile: 'ZIP compressed {ext} file'
|
||||
},
|
||||
faker: {
|
||||
address: 'Address',
|
||||
|
|
Loading…
Reference in New Issue